Skip to content

Exception handling

When a system step fails, Process Focus can retry it. If it runs out of retries or reports a non-retryable error, the process follows a matching error branch. Without a matching branch, Process Focus marks both the step’s To-Do and the execution as Failed.

Set retries on a NodeStep to control how many times Process Focus can retry after the initial attempt. Omit it to use the runtime default or set it to 0 to disable automatic retries.

Retries are useful for temporary failures, such as a service being unavailable. For a failure that another attempt won’t fix, return a tagged error with retryable: false. For example, a stock reservation step can return this from execute if the supplier confirms the item is discontinued:

import { Effect } from "effect"
return Effect.fail({
_tag: "ItemDiscontinued",
retryable: false,
})

If the step writes to an external system, use an idempotency key when the service supports one. A timeout can occur after the service has accepted the write.

Use onError on the system step to connect a recovery step. Here, a successful reservation goes to confirmDispatch. An ItemDiscontinued error skips retries and goes to reviewOrder, a form where someone can decide how to handle the order.

orderFulfilment.start(receiveOrder).next(reserveStock).next(confirmDispatch).end()
reserveStock.onError(reviewOrder, {
taggedErrors: ["ItemDiscontinued"],
}).end()

taggedErrors matches the error’s _tag. Omit it for a catch-all branch, which runs only if no tagged branch matches. A retryable failure can reach an error branch only after its retries are exhausted.

Configure execution failure notifications to email the responsible roles. After fixing the cause, an authorised user can restart the execution from the Dashboard. Restarting retries failed work in the same execution; it does not undo changes an earlier attempt made.