Skip to main content
Runtime errors are thrown by the Workflow DevKit when internal operations fail. These errors indicate issues with API requests, workflow execution, or system state.

WorkflowError

The base class for all Workflow DevKit errors. Use with instanceof or the .is() method to catch any Workflow-related error.

Basic Usage

API Reference

Properties:
  • name - Always "WorkflowError"
  • message - Error message with optional documentation link
  • cause - The underlying error that caused this error (if any)
  • stack - Stack trace including cause chain
Methods:
  • WorkflowError.is(value) - Type guard to check if value is a WorkflowError
Constructor:

Examples

WorkflowAPIError

Thrown when HTTP requests to the Workflow backend fail due to network issues, invalid requests, or server errors.

Basic Usage

API Reference

Properties:
  • name - Always "WorkflowAPIError"
  • message - Error message
  • status - HTTP status code (e.g., 404, 500)
  • code - Error code from the API
  • url - The URL that was requested
  • retryAfter - Retry-After value in seconds (present on 429 responses)
  • cause - The underlying error (if any)
Methods:
  • WorkflowAPIError.is(value) - Type guard to check if value is a WorkflowAPIError

Examples

WorkflowRunFailedError

Thrown when a workflow run fails during execution. The cause property contains the underlying error with its message, stack trace, and optional error code.

Basic Usage

API Reference

Properties:
  • name - Always "WorkflowRunFailedError"
  • message - Error message including run ID
  • runId - The ID of the failed workflow run
  • cause - The underlying error that caused the workflow to fail
    • message - Error message
    • stack - Stack trace
    • code - Optional error code
Methods:
  • WorkflowRunFailedError.is(value) - Type guard

Examples

WorkflowRunNotCompletedError

Thrown when attempting to access the result of a workflow that hasn’t completed yet.

Basic Usage

API Reference

Properties:
  • name - Always "WorkflowRunNotCompletedError"
  • message - Error message
  • runId - The ID of the incomplete workflow run
  • status - Current status (e.g., "running", "waiting")
Methods:
  • WorkflowRunNotCompletedError.is(value) - Type guard

Examples

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

Properties:
  • name - Always "WorkflowRuntimeError"
  • message - Error message with optional documentation link
  • cause - The underlying error (if any)
Methods:
  • 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
See the Error Reference for detailed troubleshooting guides.

WorkflowRunNotFoundError

Thrown when attempting to access a workflow run that doesn’t exist.

Basic Usage

API Reference

Properties:
  • name - Always "WorkflowRunNotFoundError"
  • message - Error message
  • runId - The ID of the missing workflow run
Methods:
  • WorkflowRunNotFoundError.is(value) - Type guard

Examples

WorkflowRunCancelledError

Thrown when attempting to get results from a cancelled workflow run.

Basic Usage

API Reference

Properties:
  • name - Always "WorkflowRunCancelledError"
  • message - Error message
  • runId - The ID of the cancelled workflow run
Methods:
  • WorkflowRunCancelledError.is(value) - Type guard

Examples

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

Properties:
  • name - Always "RunNotSupportedError"
  • message - Error message with upgrade instructions
  • runSpecVersion - The spec version required by the run
  • worldSpecVersion - The spec version supported by current World
Methods:
  • RunNotSupportedError.is(value) - Type guard

Examples

Error Checking Patterns

Using instanceof

Using Type Guards

Comprehensive Error Handling

Best Practices

  1. Use type guards for cross-context safety
    • .is() methods work reliably across different module contexts
    • Safer than instanceof in some edge cases
  2. Check specific errors before generic ones
    • Check WorkflowRunFailedError before WorkflowError
    • Order matters when using inheritance-based checks
  3. Inspect error properties for details
    • Use status, code, runId for specific handling
    • Check retryAfter on API errors for rate limits
    • Access cause for underlying error details
  4. Log full error context
    • Include error.message, error.cause, and relevant properties
    • Helps debugging and monitoring
  5. Handle version errors proactively
    • Catch RunNotSupportedError and provide upgrade instructions
    • Monitor for version mismatches in production