fix(housekeeping): preserve frozen operation errors

This commit is contained in:
Simo committed 2026-08-26 22:07:00 +02:00
1 parent 483d5b8c67
commit b5957015e7
2 files changed
+20 -4

No files matched your search

@@ -129,4 +129,16 @@ describe("audit command envelope", () => {
auditOutcomeError: auditFailure,
});
});
it("preserves a frozen operation error when failure evidence rejects", async () => {
const original = Object.freeze(new Error("operation failed"));
const writer: HousekeepingAuditWriter = {
write: vi
.fn()
.mockResolvedValueOnce(undefined)
.mockRejectedValueOnce(new Error("audit failure")),
};
await expect(
runWithAuditIntent(writer, auditEntry, () => Promise.reject(original)),
).rejects.toBe(original);
});
});
@@ -50,10 +50,14 @@ export async function runWithAuditIntent<T>(
await writeOutcome(writer, entry, "failure", transaction);
} catch (auditOutcomeError) {
if (error instanceof Error) {
Object.defineProperty(error, "auditOutcomeError", {
value: auditOutcomeError,
configurable: true,
});
try {
Object.defineProperty(error, "auditOutcomeError", {
value: auditOutcomeError,
configurable: true,
});
} catch {
// Frozen or non-extensible errors still preserve their original identity.
}
}
}
throw error;