PSFalcon provides comprehensive error handling for API responses, parameter validation, and runtime exceptions. Errors are written to PowerShell’s error stream with detailed context to help troubleshoot issues.
Errors returned from the Falcon API in the errors property of the response.From /home/daytona/workspace/source/private/Private.ps1:1328-1340:
# API errors are extracted from the response and written to the error stream# Each error includes:# - Error message from the API# - trace_id for troubleshooting with CrowdStrike support# - Original request context
Parameter Validation Errors
Errors from invalid parameter values, patterns, or combinations.
# Example: Invalid ClientId patternRequest-FalconToken -ClientId 'invalid'# Error: The argument "invalid" does not match the "^[a-fA-F0-9]{32}$" pattern
FQL (Falcon Query Language) Errors
Validation errors for malformed filter expressions.From /home/daytona/workspace/source/private/Private.ps1:1182-1197:
# FQL statements are validated before submissionGet-FalconHost -Filter 'invalid syntax'# Error: 'invalid syntax' is not a valid Falcon Query Language statement
Runtime Errors
Errors from missing dependencies, network issues, or unexpected conditions.
From /home/daytona/workspace/source/private/Private.ps1:1307-1365, PSFalcon’s Write-Result function processes API responses:
1
Response Processing
Every API response is parsed for:
meta - Metadata including pagination and trace_id
errors - Array of error objects
resources - The actual data payload
2
Error Extraction
If errors are present in the response:
# Each error is converted to a PowerShell ErrorRecord# - Exception message: JSON representation of the error# - ErrorId: trace_id from meta.trace_id# - Category: InvalidResult# - TargetObject: The original request
3
Error Stream Output
Errors are written to PowerShell’s error stream using $PSCmdlet.WriteError().This allows you to:
# Suppress errors and continue$Result = Get-FalconHost -Filter "invalid" -ErrorAction SilentlyContinueif (!$Result) { Write-Warning "No results returned or error occurred"}
Control error behavior using PowerShell’s -ErrorAction parameter:
Available ErrorAction Values
Value
Behavior
Continue
Display error and continue (default)
SilentlyContinue
Suppress error, continue execution
Stop
Display error and halt execution
Inquire
Prompt user for action
Ignore
Suppress error, don’t add to $Error
# Stop on any errorGet-FalconHost -Filter "invalid" -ErrorAction Stop# Suppress and continueGet-FalconHost -Filter "invalid" -ErrorAction SilentlyContinue# Set for entire session$ErrorActionPreference = 'Stop'
From /home/daytona/workspace/source/private/Private.ps1:658-660:
# If pagination token is missing mid-request, PSFalcon throws an error:# "Aborted due to missing pagination token. [Retrieved X of Y]"try { Get-FalconHost -All} catch { if ($_.Exception.Message -match 'missing pagination token') { Write-Warning "Pagination interrupted. Partial results may be available." }}
Many PSFalcon commands support -WhatIf to preview actions:
# Preview without executingRequest-FalconToken -ClientId $Id -ClientSecret $Secret -WhatIf# Output shows what would be executed:# What if: Performing the operation "POST" on target "..."