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

Errors.test.ts

49 lines1.6 KB

1import { assert, it } from "@effect/vitest";
2import * as Effect from "effect/Effect";
3import * as Schema from "effect/Schema";
4​
5import { PersistenceDecodeError, PersistenceSqlError } from "./Errors.ts";
6​
7const decodeRuntimePayload = Schema.decodeUnknownEffect(
8 Schema.Struct({
9 runtimePayload: Schema.Struct({
10 attempt: Schema.Number,
11 }),
12 }),
13);
14​
15it("keeps SQL operation context without a tautological detail", () => {
16 const cause = new Error("database unavailable");
17 const error = new PersistenceSqlError({
18 operation: "AuthSessionRepository.list:query",
19 cause,
20 });
21​
22 assert.equal(error.operation, "AuthSessionRepository.list:query");
23 assert.equal(error.detail, undefined);
24 assert.equal(error.cause, cause);
25 assert.equal(error.message, "SQL error in AuthSessionRepository.list:query");
26});
27​
28it.effect("maps schema errors without copying rejected payloads into diagnostics", () =>
29 Effect.gen(function* () {
30 const rejectedPayload = "runtime-payload-secret-sentinel";
31 const cause = yield* Effect.flip(
32 decodeRuntimePayload({
33 runtimePayload: {
34 attempt: rejectedPayload,
35 },
36 }),
37 );
38 const error = PersistenceDecodeError.fromSchemaError(
39 "ProviderSessionRuntimeRepository.list:decodeRows",
40 cause,
41 );
42​
43 assert.equal(error.operation, "ProviderSessionRuntimeRepository.list:decodeRows");
44 assert.equal(error.cause, cause);
45 assert.notInclude(error.issue, rejectedPayload);
46 assert.notInclude(error.message, rejectedPayload);
47 assert.include(error.issue, "InvalidType");
48 }),
49);