Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): surface the cause behind a persistence SQL error #4837

ClosedSy-D(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/4837/headopened View on GitHub

Showing 2 changed files with 86 additions and 4 deletions.

x
0 of 2 viewed, 2 left
51 additions and 1 deletionapps/server/src/persistence/Errors.test.tsModified
View file
@@ -2,7 +2,7 @@
import * as Effect from "effect/Effect";
import * as Schema from "effect/Schema";
​
-import { PersistenceDecodeError, PersistenceSqlError } from "./Errors.ts";
+import { PersistenceDecodeError, PersistenceSqlError, toPersistenceSqlError } from "./Errors.ts";
​
const decodeRuntimePayload = Schema.decodeUnknownEffect(
Schema.Struct({
@@ -25,6 +25,56 @@
assert.equal(error.message, "SQL error in AuthSessionRepository.list:query");
});
​
+it("names the SQLite condition by its normalized result code", () => {
+ const cause = Object.assign(new Error("UNIQUE constraint failed: orders.customer_email"), {
+ errcode: 1555,
+ errstr: "constraint failed",
+ });
+ const error = toPersistenceSqlError("OrchestrationCommandReceiptRepository.upsert:query")(cause);
+​
+ assert.equal(error.detail, "SQLITE(1555) constraint failed");
+ assert.equal(error.cause, cause);
+});
+​
+it("reads the condition through a wrapping driver error", () => {
+ const driver = Object.assign(new Error("locked"), { errcode: 5, errstr: "database is locked" });
+ const error = toPersistenceSqlError("AuthSessionRepository.list:query")(
+ new Error("Failed to prepare statement", { cause: driver }),
+ );