Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/__tests__/testing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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/);
});
});
3 changes: 2 additions & 1 deletion src/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -256,7 +257,7 @@ export const decodeWorkflowResult = <W extends Workflow.Any>(
// SAFETY: the exit was decoded through the workflow's own success schema,
// so the success value is SuccessOf<W> — the codec seam types it unknown.
if (Exit.isSuccess(exit)) return exit.value as SuccessOf<W>;
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)}`);
};

/**
Expand Down