Skip to content

errors

errors

Carry a deferred worker exception back to the trace that wrote it.

A deferring interleaver (defer_exceptions) records a worker's exception on its mediator instead of raising it out of the hook, so the driver can end just that worker's request. The error still has to reach the client that wrote the intervention — which may be another process — so it is reduced to a plain, picklable dict in the worker and re-raised at the client.

What the client catches is a RuntimeError whose message starts with the original type name and message, so a caller that needs to tell one refusal from another matches on the text rather than on the class.

A tracer.stop() raises EarlyStopException, which travels the same path but is control flow, not an error: it is marked and never re-raised.

DeferredError

Bases: TypedDict

type_name instance-attribute

type_name: str

message instance-attribute

message: str

traceback instance-attribute

traceback: str

is_control_flow instance-attribute

is_control_flow: bool

capture_exception

capture_exception(exception: BaseException) -> DeferredError

Reduce a worker's exception to a wire-safe dict.

Uses the intervention-only traceback stashed by switch when present, so the surfaced trace points at the user's line rather than the model/hook stack.

raise_deferred

raise_deferred(error: Optional[DeferredError]) -> None

Re-raise a captured worker error at the client; a stop returns silently.

Raised as a RuntimeError carrying the original type, message, and intervention traceback rather than reconstructing the original class, which is brittle across a process boundary.