UNPKG

workflow

Version:

Workflow SDK - Build durable, resilient, and observable workflows

63 lines (50 loc) • 1.97 kB
--- title: WorkflowRunFailedError description: Thrown when awaiting the return value of a failed workflow run. type: reference summary: Catch WorkflowRunFailedError when awaiting run.returnValue on a run that encountered a fatal error. related: - /docs/api-reference/workflow/fatal-error - /docs/api-reference/workflow-errors/workflow-run-cancelled-error - /docs/api-reference/workflow-errors/workflow-run-not-found-error --- `WorkflowRunFailedError` is thrown when awaiting `run.returnValue` on a workflow run whose status is `'failed'`. This indicates that the workflow encountered a fatal error during execution and cannot produce a return value. The `cause` property contains the underlying error with its message, stack trace, and optional error code. ```typescript lineNumbers import { WorkflowRunFailedError } from "workflow/errors" declare const run: { status: Promise<string>; returnValue: Promise<any> }; // @setup try { const result = await run.returnValue; } catch (error) { if (WorkflowRunFailedError.is(error)) { // [!code highlight] console.error(`Run ${error.runId} failed:`, error.cause.message); if (error.cause.code) { console.error("Error code:", error.cause.code); } } } ``` ## API Signature ### Properties <TSDoc definition={` interface WorkflowRunFailedError { /** The ID of the failed run. */ runId: string; /** The underlying error that caused the failure. */ cause: Error & { code?: string }; /** The error message. */ message: string; } export default WorkflowRunFailedError;`} /> ### Static Methods #### `WorkflowRunFailedError.is(value)` Type-safe check for `WorkflowRunFailedError` instances. Preferred over `instanceof` because it works across module boundaries and VM contexts. ```typescript import { WorkflowRunFailedError } from "workflow/errors" declare const error: unknown; // @setup if (WorkflowRunFailedError.is(error)) { // error is typed as WorkflowRunFailedError } ```