Interface IErrorContext<T>

Iteration Error Context.

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

Type Parameters

  • T

Hierarchy

  • IErrorContext

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