Interface ErrorHandler<Input, Output>

The interface that an error handler must implement to be able to be used. It includes three methods:

  1. registerCycleError: Used to register an error that has occurred while iterating through the generator
  2. registerOpError: Used to register an error if it occurs while performing on operation
  3. compile: After iterating through the array and performing operations, return the data in a different form.

NOTE: Because I was having difficulties with TypeScript types, you might not get the correct types if you want to implement your own error handlers, c.f. Issue #27.

interface ErrorHandler<Input, Output> {
    compile<Data>(data: Data): Output;
    registerCycleError(error: unknown, index: number): void;
    registerOpError(error: unknown, index: number, item: undefined | Input, op: string): void;
}

Type Parameters

  • Input
  • Output

Implemented by

Methods

  • When compiling the final data, the handler might affect the final shape of the data.

    Type Parameters

    • Data

    Parameters

    Returns Output

  • Used to register an error that has occurred while iterating through the generator, i.e.

    function* gen() {
    yield 1;
    throw new Error("test error");
    }

    Parameters

    • error: unknown
    • index: number

    Returns void

  • Used to register an error if it occurs while performing on operation an item yielded by the generator, i.e.

    function* gen() {
    yield 1;
    throw new Error("test error");
    }

    Parameters

    • error: unknown
    • index: number
    • item: undefined | Input
    • op: string

    Returns void