import assert from "node:assert/strict"; import test from "node:test"; import { sanitizedErrorReason } from "../src/lib/safe-error-reason.ts"; test("sanitizedErrorReason reads PostgREST code/hint from non-Error objects", () => { assert.equal(sanitizedErrorReason("boom"), "UnknownError"); assert.equal(sanitizedErrorReason(new Error("secret row")), "Error"); assert.equal( sanitizedErrorReason({ code: "42703", hint: "column does not exist" }), "UnknownError code=42703 hint=column does not exist", ); assert.equal( sanitizedErrorReason({ name: "PostgrestError", code: "PGRST204", hint: "" }), "PostgrestError code=PGRST204 hint=none", ); assert.doesNotMatch( sanitizedErrorReason({ code: "42703", message: "row body must not be logged", details: "secret" }), /row body|secret/, ); });