Open this lesson on a wider screen to play it. The narrated transcript and animated code need room to sit side by side.
← All lessonsimport { Data, Effect } from "effect";
class MissingId extends Data.TaggedError("MissingId")<{}> {}
class NotFound extends Data.TaggedError("NotFound")<{}> {}
const lookup = (id: string): Effect.Effect<string, MissingId | NotFound> =>
id === "" ? Effect.fail(new MissingId()) : Effect.succeed("Ada");
// catchAll handles EVERY failure with a recovery effect. Once nothing can
// fail, the error channel collapses to never.
const safe: Effect.Effect<string> = lookup("").pipe(
Effect.catchAll(() => Effect.succeed("anonymous")),
);
console.log(Effect.runSync(safe)); // anonymous