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";
// An EXPECTED error is a case you planned for. It lives in the E channel,
// the compiler tracks it, and you recover from it like normal.
class Timeout extends Data.TaggedError("Timeout")<{}> {}
const fetchUser: Effect.Effect<string, Timeout> = Effect.fail(new Timeout());
const program = fetchUser.pipe(
Effect.catchTag("Timeout", () => Effect.succeed("cached user")),
);
console.log(Effect.runSync(program)); // cached user