Interface IErrorContext<T>

Iteration Error Context.

It is passed into every error handler as the second parameter.

interface IErrorContext<T> {
    index: number;
    lastValue?: T;
    repeats: number;
    state: IterationState;
    emit(value: T): void;
}

Type Parameters

  • T

Properties

Methods

Properties

index: number

Index of the value that threw an error.

lastValue?: T

Last successfully retrieved value, if any (undefined otherwise).

repeats: number

Number of times the error has been repeated (starts with 0).

It helps to detect when an iterator starts throwing the same error in a loop, so a different error-handling strategy can be applied, such as (for example) re-throwing only when the error is repeated.

.catch((e, ctx) => {
if(ctx.repeats) {
throw e; // re-throw when repeated
}
console.log(e?.message || e); // report the error
});

Iteration state, persisted through entire iteration session.

Methods

  • Alternative value emitter, to replace what we failed to retrieve. Without this call, the errored value is skipped from iteration.

    Parameters

    • value: T

    Returns void