variable / @typed/template

EventHandler.catchCause

Recovers from errors in the EventHandler.

Package version
1.0.0-beta.7
Category
Handler failure recovery
Since
1.0.0
Member of
EventHandler

Import

import { EventHandler } from "@typed/template";

Access EventHandler.catchCause through the imported EventHandler export. Its declaration below describes the member.

This public exposure is a re-export. Its import path is supported; declaration documentation is shared with the other public exposures below.

Signatures

export declare const catchCause: {
    <E, E2 = never, R2 = never>(f: (cause: Cause.Cause<E>) => Effect.Effect<unknown, E2, R2>): <Ev extends Event, R = never>(handler: EventHandler<Ev, E, R>) => EventHandler<Ev, E2, R | R2>;
    <Ev extends Event, E = never, R = never, E2 = never, R2 = never>(handler: EventHandler<Ev, E, R>, f: (cause: Cause.Cause<E>) => Effect.Effect<unknown, E2, R2>): EventHandler<Ev, E2, R | R2>;
};

Why

Handling the full Cause preserves interruption and defect information instead of reducing failures to thrown exceptions.

Ownership and lifetime

The returned description installs no listener. Recovery runs in the same handler fiber and mount Scope when a real event arrives.

Examples

import { Effect } from "effect"
import * as EventHandler from "@typed/template/EventHandler"

const handler = EventHandler.make((event) =>
  Effect.fail("Something went wrong")
)

// Recover from errors
const recovered = EventHandler.catchCause(handler, (cause) =>
  Effect.sync(() => console.error("Error:", cause))
)

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source