| 1 | import * as Cause from "effect/Cause"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import { findErrorTraceId } from "./errorTrace.ts"; |
| 5 | |
| 6 | describe("findErrorTraceId", () => { |
| 7 | it("finds trace metadata through wrapped typed errors", () => { |
| 8 | expect( |
| 9 | findErrorTraceId({ |
| 10 | cause: { |
| 11 | cause: { |
| 12 | _tag: "RelayInternalError", |
| 13 | traceId: "trace-relay", |
| 14 | }, |
| 15 | }, |
| 16 | }), |
| 17 | ).toBe("trace-relay"); |
| 18 | }); |
| 19 | |
| 20 | it("terminates for cyclic causes", () => { |
| 21 | const error: { cause?: unknown } = {}; |
| 22 | error.cause = error; |
| 23 | |
| 24 | expect(findErrorTraceId(error)).toBeNull(); |
| 25 | }); |
| 26 | |
| 27 | it("finds trace metadata in Effect cause branches", () => { |
| 28 | const cause = Cause.fromReasons<unknown>([ |
| 29 | Cause.makeFailReason(new Error("first failure")), |
| 30 | Cause.makeFailReason({ traceId: "trace-secondary" }), |
| 31 | ]); |
| 32 | |
| 33 | expect(findErrorTraceId(cause)).toBe("trace-secondary"); |
| 34 | }); |
| 35 | |
| 36 | it("finds trace metadata in aggregate error branches", () => { |
| 37 | const error = new AggregateError( |
| 38 | [new Error("first failure"), { traceId: "trace-aggregate" }], |
| 39 | "request failed", |
| 40 | ); |
| 41 | |
| 42 | expect(findErrorTraceId(error)).toBe("trace-aggregate"); |
| 43 | }); |
| 44 | }); |