Skip to Content
Runlane
ReferenceApplication API

Errors

Construct Runlane errors, control retries, and read stored failures.

Import ErrorCode and RunlaneError from @runlane/core.

Local development storage errors

Without runlane dev, the first createLocalLane() storage operation rejects with storage_unavailable. The message names the searched config path:

runlane dev is not running for <config path>. Start it with "runlane dev", then retry. In tests, use createTestLane().

The failed trigger saves no run. Start dev for that config and retry in the same app process. If dev is starting or stopping, wait for it to finish and retry. A disconnected lane never falls back to app memory. Restarting dev clears its runs; later operations reconnect to fresh memory.

If dev serves a different lane name than the app, operations reject with configuration_invalid and name both lanes. Use the same name in the app and the config's runtime.

For tests without dev, use createTestLane(). Same-name test handles must use the same clock function; conflicting clocks reject with configuration_invalid.

Construct an error

Use RunlaneError when a task needs to save a public reason or state whether a failure can be retried:

import { ErrorCode, RunlaneError } from '@runlane/core'

throw new RunlaneError({
  code: ErrorCode.TaskFailed,
  message: 'The account no longer exists.',
  retryable: false,
  meta: { reason: 'account_deleted' },
})

The constructor accepts RunlaneErrorOptions:

FieldType and default
codeRequired ErrorCode.
messageOptional string. Defaults to the code.
retryableOptional boolean. Defaults to false.
causeOptional original thrown value, kept for internal diagnosis.
metaOptional JsonObject with safe, structured context.

The instance extends Error and exposes these fields. Use error instanceof RunlaneError before reading them. Every instance carries Symbol.for('runlane.error'). The base-class check works across package copies. Subclasses keep normal prototype checks, so sibling subclasses remain distinct. Match error.code, not message text. If you catch another kind of error, treat it as an unexpected application or dependency failure.

Realtime and React use the same class and ErrorCode values. Import them from @runlane/realtime or @runlane/realtime/client. A resume checkpoint is in error.meta?.cursor. Unexpected reader failures use internal_error and preserve the original value as cause.

Task handlers and token callbacks share one retry rule: a plain Error means a temporary failure. Runlane retries it while a budget remains. A RunlaneError stops retries unless retryable: true.

Thrown errors and stored failures

Public operations such as trigger() reject when setup, validation, or storage fails before a confirmed commit. After a confirmed commit, a delivery failure returns success with deliveryError; do not repeat the saved change. See saved changes and delivery errors.

Handler failures are normally saved on the run. runNow() executes one attempt and returns a RunRecord; a failed handler does not normally make that call reject. Check the returned run's status and failure, or read the run later through runlane.runs.get().

A stored RunFailure keeps the thrown error's name, message, and stack. Plain errors use code: task_failed and the task's retry policy. RunlaneError also keeps its code, retryable, and meta. Strings keep their text; other thrown values use safe inspection that does not call custom inspectors or getters. Non-error throws receive an Error identity and a stack captured when Runlane handles them.

Messages and names are capped at contractDefaults.run.failureMessageMaxLength UTF-16 code units. Stacks use contractDefaults.run.failureStackMaxLength. Runlane replaces U+0000 (NUL) in names, messages, and stacks with U+FFFD before applying length limits so every lane can store failures. Invalid Unicode and NUL in failure metadata values and keys are also replaced with U+FFFD; if replacement produces duplicate keys, the last key wins. It also replaces unmatched UTF-16 halves, including those left by truncation, with U+FFFD. Empty error messages remain empty. Causes are not copied. Older records and system-generated failures may omit name and stack. See defaults for current limits.

Each run.retry_scheduled and run.failed event stores that attempt's failure through the storage driver. Server-side operators and CLI JSON can read the stack. Browser snapshots and status deltas expose only name, code, message, and retryable, with the Output permission. They never expose stacks or failure metadata. Keep secrets and raw provider responses out of thrown messages: messages are stored and may be shown to those users.

Invalid options passed to task-context waits or steps throw configuration_invalid. For unrecognized option names, meta.unsupportedOptions lists those names. If the handler lets the error escape, that metadata is saved with the failure.

Updating metadata or tags on a terminal run rejects with validation_failed.

Shared not-found messages

notFoundErrorMessages from @runlane/contracts owns the public text for required missing resources. Read its fields when constructing provider or operator errors:

FieldMeaning
runA required run was not found.
taskThe task is not registered in this runtime.
waitTokenA required wait token was not found.

Match the error code when handling failures; the message is for readers. Optional reads can return undefined instead, as described in runs and waits.

Outcomes that exceed storage limits

If storage rejects a handler's output, release reason or metadata, or failure metadata for size, Runlane saves a non-retryable storage_limit_exceeded failure instead. This also applies when that failure would otherwise schedule a retry. Its message is "Task outcome is too large to store. Store large values outside Runlane and save a reference."

failure.meta contains only actual, limit, and outcome. The measurements use the same unit, bytes or records. The outcome is success, release, or failed; failed includes a rejected retry-scheduled failure. The oversized value is not saved. Other runs sharing a persistence batch can still succeed, and a waiting parent receives the child's stored failure through join().

If the replacement failure cannot be saved either, the storage error still rejects the execution call. Other persistence errors keep their usual handling.

Retry decisions

Handler resultAutomatic retry behavior
Ordinary thrown Error, with a task retry policyRetries while run.counters.retries is below the policy's maxRetries.
RunlaneError with retryable: trueRetryable only if the task also has a retry policy and budget remains.
RunlaneError with retryable: false or no retryable fieldEnds as failed without automatic retry.
Any failure with no task retry policyNo automatic retry.
Crash allowance exceededRecords task_interrupted with retryable: false. The run fails even if failure retries remain.
Attempt deadline expiresRecords task_timed_out. Retries if the task policy allows another attempt; otherwise ends as failed.
Awaited release or pending waitEnds the attempt without recording a failure, spending retry budget, or increasing retry backoff.

Mark a failure retryable only if repeating the work can help. The retry guide shows both temporary and permanent failures in one task.

Error codes

These members belong to ErrorCode. Their stored values use snake case.

MemberStored valueMeaning
AccessDeniedaccess_deniedThe caller or scoped token cannot read the run.
DisconnecteddisconnectedA realtime connection failed or exhausted its retry budget.
EventTooLargeevent_too_largeOne serialized realtime event exceeds the byte limit.
WireInvalidwire_invalidA realtime response does not match the wire contract.
AdapterContractViolationadapter_contract_violationAn adapter returned data or behavior outside its contract.
CapabilityUnsupportedcapability_unsupportedThe configured lane or provider does not support the operation.
ConfigurationInvalidconfiguration_invalidA definition or option is invalid.
InternalErrorinternal_errorAn internal operation failed.
InvariantViolationinvariant_violationStored or runtime state violates a required rule.
OperationCancelledoperation_cancelledAn operation was cancelled.
ObservationExportFailedobservation_export_failedExporting observations failed.
RunIdConflictrun_id_conflictA requested run ID conflicts with another task, an idempotency owner, or an existing linked-run ID. Retryable only while a pruned run's ID awaits cleanup. See run ID conflicts.
RunNotFoundrun_not_foundAn operation requires a run that does not exist. A plain runs.get() returns undefined instead.
LogLimitExceededlog_limit_exceededAn individual log body exceeds logs.maxEntryBytes. Run-wide quotas truncate logs instead of failing execution.
ScheduleConflictschedule_conflictA schedule deduplication key belongs to a different definition; use update.
QueuePausedqueue_pausedrunNow() refused a paused queue. Nothing was saved. Not retryable until the queue is resumed; call trigger() to queue the work instead. Metadata contains queue and taskId. A delivery Retry for a paused queue uses the same code with retryable: true; the provider keeps redelivering on its normal backoff until the queue resumes.
QueueAtCapacityqueue_at_capacityrunNow() refused a full total or per-key pool. Nothing was saved. Retryable; retry later or call trigger() to queue the work. Metadata contains queue and taskId. A delivery Retry for a full queue uses the same code.
StorageConflictstorage_conflictA concurrent write or ownership claim conflicted.
StorageLimitExceededstorage_limit_exceededAn operation is larger than storage can hold or commit atomically. meta.actual and meta.limit report the measured size and the limit in the same unit. Not retryable.
StorageUnavailablestorage_unavailableStorage could not serve the operation.
TaskFailedtask_failedThe task handler failed.
TaskInterruptedtask_interruptedWorker shutdown abort reasons from createWorkerShutdownError() are retryable. An execution or delivery signal abort before the handler error makes it an interruption, whatever the abort reason. See Stop crash loops for the interruption allowance. Exceeding a finite allowance records a non-retryable failure; no new attempt starts.
TaskNotFoundtask_not_foundThe runtime cannot find the task definition.
TaskOutputInvalidtask_output_invalidTask output does not match its schema or storage format.
TaskTimedOuttask_timed_outAn attempt exceeded its time limit, or a joined run missed its first-start deadline.
TransportPublishFailedtransport_publish_failedPublishing a delivery request failed.
TransportUnavailabletransport_unavailableThe delivery service is unavailable.
ValidationFailedvalidation_failedA payload or other operation input failed validation.
WaitTimedOutwait_timed_outOne signal wait or token wait window reached its timeout. A token window leaves the token pending.
WaitTokenExpiredwait_token_expiredThe token reached its own creation deadline before completion.
WaitTokenNotFoundwait_token_not_foundAn operation requires a missing wait token. A plain token read returns undefined instead.
WaitTokenOutputInvalidwait_token_output_invalidA completed token's output does not match the requested schema.

Use the error's retryable field and the operation's state to decide what to do next. An error code alone is not a promise that retrying is safe.

Run ID conflicts

A raw trigger with an existing runId returns that run when it belongs to the same task, in any status. run_id_conflict means the requested run ID can't be used:

  • The ID belongs to a run of another task.
  • The call's idempotency key, from the call or the task, belongs to a different run.
  • A named child step requests an ID that a stored run already has. Named steps don't reuse runs by ID. The exception is a step whose idempotency key already points to that same run, which returns it.
  • runs.retry() or runs.rerun() requests an ID that is already taken.
  • The ID belongs to a pruned run that cleanup hasn't removed yet.

Retrying the same call can't fix the first four cases, so choose the intended run identity. The pruned case is retryable: the ID is free again after cleanup.

Schedule conflicts

schedule_conflict means a runtime schedule's environment-scoped deduplication key belongs to a different definition. Identical keyed creates return the existing schedule. Replace a definition through schedules.update(); externalId is a nonunique label. Invalid timing, zones, and declared definition mutations use configuration_invalid.

Log limits

log_limit_exceeded means an individual log body exceeds logs.maxEntryBytes. This rejection throws at a context.logger call. Console capture reports the rejected record through runtime telemetry without throwing into task code. Run-wide entry and byte quotas save one truncation marker and drop later entries without failing an attempt or hook.

Stream and cursor errors

Stream and cursor codeStored valueMeaning
StreamLimitExceededstream_limit_exceededA normalized chunk, name count, run byte count, or record count exceeded its stream quota.
RunCursorInvalidrun_cursor_invalidA source cursor is malformed or belongs to another reader, environment, run, or retained instance, or exceeds a source tail.

On this page