API · Errors
stopOnError()
Pass successful values until the first record error, handle it once, then stop this branch.
Signature
stopOnError<U = T>(
fn: (error: ExstreamError<T>, push: Push<U, C>, context: C) => void,
): Exstream<T | U, C> Example
const partial = exstream(rows)
.map(parseRow)
.stopOnError((error, push) => {
push(null, { stopped: true, reason: error.message })
}) Parameters
fnCalled only for the first record error. Use
push(null, replacement)to emit replacement data,push(otherError)to emit an error, or do not push to swallow it.
Behavior
Successful values before the error pass through. After fn returns, this branch is destroyed regardless of what it pushed; no later source values are consumed here. This is local branch termination, not automatic fatal failure, so sibling forks may continue.
The callback is synchronous. A context is supplied when it declares three parameters; if none existed, Exstream creates one from the error’s original input. Pushed replacements use that context by default.
Callback errors
The implementation does not wrap exceptions thrown by fn; keep the handler non-throwing. Existing fatal failures bypass it. For a handler that can process multiple errors and continue, use errors().
Forms
stream.stopOnError(handler)
exstream.pipeline().stopOnError(handler)
exstream.stopOnError(handler, stream)
stream.through(exstream.stopOnError(handler))