diff --git a/src/__tests__/testing.test.ts b/src/__tests__/testing.test.ts index f73f3ed..52eb47e 100644 --- a/src/__tests__/testing.test.ts +++ b/src/__tests__/testing.test.ts @@ -3,9 +3,11 @@ // everything unconfigured. import * as Effect from "effect/Effect"; +import * as Exit from "effect/Exit"; import { describe, expect, it } from "vitest"; import { makeWorkflowClient } from "../client.js"; import { decodeWorkflowResult, makeFakeTemporalClient, simulateAlreadyStarted } from "../testing.js"; +import { wireCodecsFor } from "../wire.js"; import { Demo } from "./fixtures/demo.js"; const payload = { requestId: "fake-1", mode: "approve" } as const; @@ -85,4 +87,10 @@ describe("decodeWorkflowResult", () => { }), ).toThrow(/did not succeed/); }); + + it("preserves native defect details in the thrown message", () => { + const wire = wireCodecsFor(Demo).encodeExit(Exit.die(new Error("boom"))); + + expect(() => decodeWorkflowResult(Demo, wire)).toThrow(/boom/); + }); }); diff --git a/src/testing.ts b/src/testing.ts index 3377632..8ffa80a 100644 --- a/src/testing.ts +++ b/src/testing.ts @@ -14,6 +14,7 @@ * @since 0.1.0 */ +import * as Cause from "effect/Cause"; import * as Effect from "effect/Effect"; import * as Exit from "effect/Exit"; import type * as Schema from "effect/Schema"; @@ -256,7 +257,7 @@ export const decodeWorkflowResult = ( // SAFETY: the exit was decoded through the workflow's own success schema, // so the success value is SuccessOf — the codec seam types it unknown. if (Exit.isSuccess(exit)) return exit.value as SuccessOf; - throw new Error(`workflow "${workflow._tag}" did not succeed: ${JSON.stringify(exit.cause)}`); + throw new Error(`workflow "${workflow._tag}" did not succeed: ${Cause.pretty(exit.cause)}`); }; /**