WorkflowError
The base class for all Workflow DevKit errors. Use withinstanceof or the .is() method to catch any Workflow-related error.
Basic Usage
API Reference
WorkflowError Class
WorkflowError Class
name- Always"WorkflowError"message- Error message with optional documentation linkcause- The underlying error that caused this error (if any)stack- Stack trace including cause chain
WorkflowError.is(value)- Type guard to check if value is a WorkflowError
Examples
Catching Any Workflow Error
Catching Any Workflow Error
WorkflowAPIError
Thrown when HTTP requests to the Workflow backend fail due to network issues, invalid requests, or server errors.Basic Usage
API Reference
WorkflowAPIError Class
WorkflowAPIError Class
name- Always"WorkflowAPIError"message- Error messagestatus- HTTP status code (e.g., 404, 500)code- Error code from the APIurl- The URL that was requestedretryAfter- Retry-After value in seconds (present on 429 responses)cause- The underlying error (if any)
WorkflowAPIError.is(value)- Type guard to check if value is a WorkflowAPIError
Examples
Handling API Rate Limits
Handling API Rate Limits
Handling Different Status Codes
Handling Different Status Codes
WorkflowRunFailedError
Thrown when a workflow run fails during execution. Thecause property contains the underlying error with its message, stack trace, and optional error code.
Basic Usage
API Reference
WorkflowRunFailedError Class
WorkflowRunFailedError Class
name- Always"WorkflowRunFailedError"message- Error message including run IDrunId- The ID of the failed workflow runcause- The underlying error that caused the workflow to failmessage- Error messagestack- Stack tracecode- Optional error code
WorkflowRunFailedError.is(value)- Type guard
Examples
Accessing Failure Details
Accessing Failure Details
WorkflowRunNotCompletedError
Thrown when attempting to access the result of a workflow that hasn’t completed yet.Basic Usage
API Reference
WorkflowRunNotCompletedError Class
WorkflowRunNotCompletedError Class
name- Always"WorkflowRunNotCompletedError"message- Error messagerunId- The ID of the incomplete workflow runstatus- Current status (e.g.,"running","waiting")
WorkflowRunNotCompletedError.is(value)- Type guard
Examples
Polling for Completion
Polling for Completion
WorkflowRuntimeError
Thrown when the Workflow runtime encounters an internal error, such as serialization failures, invalid workflow functions, or other runtime problems.Basic Usage
API Reference
WorkflowRuntimeError Class
WorkflowRuntimeError Class
name- Always"WorkflowRuntimeError"message- Error message with optional documentation linkcause- The underlying error (if any)
WorkflowRuntimeError.is(value)- Type guard
Common Runtime Errors
WorkflowRuntimeError is used for various runtime issues. The error message includes a link to documentation for common errors:- Serialization failed - Non-serializable data passed between workflow boundaries
- Node.js module in workflow - Attempted to use Node.js modules in workflow functions
- fetch in workflow - Attempted to use global fetch instead of workflow fetch
- Timeout functions in workflow - Used setTimeout/setInterval instead of sleep
- Invalid workflow function - Workflow function doesn’t have “use workflow” directive
- Hook conflict - Multiple workflows trying to use the same hook token
- Corrupted event log - Event log contains invalid or unconsumed events
WorkflowRunNotFoundError
Thrown when attempting to access a workflow run that doesn’t exist.Basic Usage
API Reference
WorkflowRunNotFoundError Class
WorkflowRunNotFoundError Class
name- Always"WorkflowRunNotFoundError"message- Error messagerunId- The ID of the missing workflow run
WorkflowRunNotFoundError.is(value)- Type guard
Examples
Handling Missing Runs
Handling Missing Runs
WorkflowRunCancelledError
Thrown when attempting to get results from a cancelled workflow run.Basic Usage
API Reference
WorkflowRunCancelledError Class
WorkflowRunCancelledError Class
name- Always"WorkflowRunCancelledError"message- Error messagerunId- The ID of the cancelled workflow run
WorkflowRunCancelledError.is(value)- Type guard
Examples
Handling Cancellations
Handling Cancellations
RunNotSupportedError
Thrown when attempting to operate on a workflow run that requires a newer World version than the current implementation supports. Users should upgrade their@workflow packages.
Basic Usage
API Reference
RunNotSupportedError Class
RunNotSupportedError Class
name- Always"RunNotSupportedError"message- Error message with upgrade instructionsrunSpecVersion- The spec version required by the runworldSpecVersion- The spec version supported by current World
RunNotSupportedError.is(value)- Type guard
Examples
Version Check and Upgrade
Version Check and Upgrade
Error Checking Patterns
Using instanceof
Using Type Guards
Comprehensive Error Handling
Best Practices
-
Use type guards for cross-context safety
.is()methods work reliably across different module contexts- Safer than
instanceofin some edge cases
-
Check specific errors before generic ones
- Check
WorkflowRunFailedErrorbeforeWorkflowError - Order matters when using inheritance-based checks
- Check
-
Inspect error properties for details
- Use
status,code,runIdfor specific handling - Check
retryAfteron API errors for rate limits - Access
causefor underlying error details
- Use
-
Log full error context
- Include
error.message,error.cause, and relevant properties - Helps debugging and monitoring
- Include
-
Handle version errors proactively
- Catch
RunNotSupportedErrorand provide upgrade instructions - Monitor for version mismatches in production
- Catch