Errors & Cancellation¶
Sentinel Errors¶
| Variable | Message | Returned / Emitted By |
|---|---|---|
ErrSkip |
"automi: skip item" |
User callbacks (FromFunc, FromSeq2, TryMap, ParMap, Step.Then, Chain, OnError, ToFunc, Each, ParEach) to drop an item without halting the pipeline. |
ErrNilSource |
"automi: nil source" |
From(nil) |
ErrNilSink |
"automi: nil sink" |
Into(ctx, nil), ToSlice(nil), ToChan(nil), SinkFunc[T](nil).Consume(...), FanOut when any sink is nil |
ErrNilFunc |
"automi: nil function" |
FromFunc, Filter, Tap, Map, TryMap, FlatMap, Through, ParMap, ParEach, Reduce, GroupBy, ToFunc, Do, Step.Then, Chain (when any element or receiver is nil) |
ErrNilReader |
"automi: nil reader" |
FromCSV(nil), FromLines(nil), FromReader(nil, ...) |
ErrNilWriter |
"automi: nil writer" |
ToCSV(nil), ToWriter(nil) |
ErrCircuitOpen |
"automi: circuit breaker open" |
Step.CircuitBreaker while the breaker is open or a single half-open probe is already active |
Additional validation errors:
RateLimit(perSec)withperSec <= 0emits"automi: rate limit must be positive".
ErrSkip Contract¶
ErrSkip uses errors.Is(err, ErrSkip) matching across all stages:
FromSeq2,FromFunc: Drops item and pulls next item.TryMap,ParMap: Drops item; inOrdered()mode, advances sequence tracking cleanly.Each,ParEach,ToFunc: IgnoresErrSkipfor the item and continues.Step.Then,Chain: Short-circuits remaining steps in the chain and returnsErrSkipimmediately.Step.Retry: Never retriesErrSkip.Step.CircuitBreaker: Does not increment failure counter or trip breaker; clearsprobeInFlightif a half-open probe returnsErrSkip.Step.OnError: Skips callinghandlerif the wrapped step returnsErrSkip. Ifhandleritself returnsnilorErrSkip,OnErrorreturnsErrSkip.
Worker Panic Recovery¶
ParMap (Workers == 1 inline fast-path, unordered, and ordered) and ParEach (both workers == 1 and concurrent pool) wrap callback invocations in recover().
A panic converts to an error formatted as:
Concurrent stages then cancel their child context, await sibling worker exit, and deliver the panic error to the terminal caller. Step.CircuitBreaker also guards half-open probe state with a defer so a panic during a probe re-opens the breaker rather than leaving probes permanently blocked.
Context Normalization and Cancellation Guarantees¶
- Nil context: Terminals (
Into,Collect,Each,ParEach,Reduce,GroupBy,All,FanOut),Step.Then,Chain, andSinkFunc.Consumetreat anilcontext.Contextascontext.Background(). - Pre-canceled contexts:
FromSlice,FromChan,FromSeq,FromSeq2,FromFunc,FromCSV,FromLines,FromReader,Step.Then,Chain,Concat,ToChan, andStep.Retrycheckctx.Err()before blocking or issuing side effects. - Sibling teardown (
errgroupsemantics): ParMap,ParEach, timedBatch,Buffer/BufferDrop,Debounce,Merge,Zip, andFanOutrun background workers undercontext.WithCancel(ctx).- First non-skip error, upstream error, consumer error, or early loop exit cancels the child context and waits via
sync.WaitGroup.Wait()(or pull stoppers inZip) before returning. - Even if workers swallow cancellation and return
ErrSkipon shutdown,ParMap,ParEach,Buffer,Debounce, timedBatch, andMergestill propagate non-nilinnerCtx.Err().