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 { Effect } from "effect";
// You can fail with any value — but a bare Error is hard to tell apart later.
const lookup = (id: string): Effect.Effect<string, Error> =>
id === "" ? Effect.fail(new Error("missing id")) : Effect.succeed("Ada");
// To branch on which failure happened you sniff the message string. Fragile.
const program = lookup("").pipe(
Effect.catchAll((err) =>
Effect.succeed(err.message === "missing id" ? "no id" : "other"),
),
);
console.log(Effect.runSync(program)); // no id