done and fail
Report a terminal outcome without returning or throwing on behalf of your function.
Signatures
run.done(options?: WorkflowDoneOptions): void
run.fail(options: WorkflowFailOptions): voidCompletion
run.done({ result: { imported: 988, skipped: 12 } })result is optional. Prefer a small reviewed summary — imported and skipped
counts, a shipment id — over passing a raw function return value.
If operations are still open, completion waits for their handles to close.
The first completion request wins and its result is preserved. New run markers
are ignored while completion is pending; existing operation handles can close.
Calling fail() supersedes pending completion.
Failure
run.fail({
code: "SUPPLIER_SYNC_FAILED",
message: "Supplier inventory could not be synchronized",
retryable: true,
result: { updated: 8, remaining: 4 },
})| Field | Meaning |
|---|---|
code | Required non-empty stable code, max 128 characters |
message | Optional safe description, max 2,048 characters |
retryable | Optional application policy for the failure |
result | Optional bounded business summary, same as done() |
code is required. Do not pass a bare string. Attach result when the
application already knows what was produced before the failure — partial
counts, reserved work, or identifiers needed to continue.
Your function is still in charge
Neither method returns from your function, throws your original exception, retries, or rolls back work:
try {
const result = await importInvoices()
run.done({ result: { imported: result.imported, skipped: result.skipped } })
return result
} catch (error) {
run.fail({ code: "IMPORT_FAILED" })
throw error
}Once terminal, later run markers are ignored.