# When a node fails

> The two ways a node fails, leaving through its error port or crashing its worker, and how each one ends the step and the run.

Source: https://docs.sommatic.ai/en/workflows/lifecycle/failures/ (updated 2026-11-26)

A node fails in one of two ways, and they end differently:

- **The node returns through its `error` port.** This is a normal result: the worker finished, the envelope has
  `port: 'error'` and the run follows the `error` edge, as for any other port (see [Errors](https://docs.sommatic.ai/en/workflows/errors.md)).
- **The worker throws.** The state machine moves it to `CRASHED` and the engine records the step as failed. Inside a
  [`flow.try`](https://docs.sommatic.ai/en/nodes/flow.try.md) scope, the run continues at its catch node with `{ error, source_node,
  source_operator }`; otherwise the whole run ends as `failed` with `Node <node_id> (<slug>) failed: <message>`.

The engine still stops a crashed worker; stopping an instance that already crashed is a no-op, so the cleanup never hides
the original error.

## How to choose

- Expect the failure and handle it in the graph: connect the node's `error` port. Most nodes catch their own errors and
  leave through `error` with the message in `data`.
- Protect a part of the graph from crashes: wrap it in [`flow.try`](https://docs.sommatic.ai/en/nodes/flow.try.md).
- Retry transient failures: use the node's `execution` settings where the node honours them (see
  [Limits](https://docs.sommatic.ai/en/workflows/limits.md)).

## Where to see it

The run's history shows each step with its status: a step that left through `error` shows its envelope; a crashed step
shows `error` with the message. The run's result records the failing node in its error.

## Next steps

- [Drafts and versions](https://docs.sommatic.ai/en/workflows/lifecycle/versions.md): From draft to an immutable version, and which mode runs what.
- [Runs and their statuses](https://docs.sommatic.ai/en/workflows/lifecycle/runs.md): The statuses of a run and of its result.
- [How a node runs](https://docs.sommatic.ai/en/workflows/lifecycle/node-execution.md): Each node is a Link Loom worker: spawn, activate, stop.
- [Worker state machine](https://docs.sommatic.ai/en/workflows/lifecycle/worker-states.md): Seven states, nine events and the hook each transition runs.
- [Isolation and sandboxes](https://docs.sommatic.ai/en/workflows/lifecycle/isolation.md): Workers, expression contexts and code sandboxes.
