Skip to content
Source
Sign inSign up
Open History to see the last commit

DefectReporter.ts

18 lines645 Bytes

1import * as Cause from "effect/Cause";
2import * as Effect from "effect/Effect";
3import * as ErrorReporter from "effect/ErrorReporter";
4​
5// RpcServer reports typed failures too; log only defects.
6const reporter: ErrorReporter.ErrorReporter = {
7 [ErrorReporter.TypeId]: ErrorReporter.TypeId,
8 report: ({ cause, fiber }) => {
9 for (const reason of cause.reasons) {
10 if (reason._tag !== "Die" || ErrorReporter.isIgnored(reason.defect)) continue;
11 Effect.runForkWith(fiber.context)(
12 Effect.logError("Unhandled defect", Cause.fromReasons([reason])),
13 );
14 }
15 },
16};
17​
18export const layer = ErrorReporter.layer([reporter]);