From b5957015e7eefdd3edf1528218688cc5e19fa5ee Mon Sep 17 00:00:00 2001 From: simoleo89 Date: Wed, 26 Aug 2026 22:07:00 +0200 Subject: [PATCH] fix(housekeeping): preserve frozen operation errors --- .../foundation/commands/audit-envelope.test.ts | 12 ++++++++++++ .../foundation/commands/audit-envelope.ts | 12 ++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/features/housekeeping/foundation/commands/audit-envelope.test.ts b/src/features/housekeeping/foundation/commands/audit-envelope.test.ts index 38b534fc..b217773a 100644 --- a/src/features/housekeeping/foundation/commands/audit-envelope.test.ts +++ b/src/features/housekeeping/foundation/commands/audit-envelope.test.ts @@ -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); + }); }); diff --git a/src/features/housekeeping/foundation/commands/audit-envelope.ts b/src/features/housekeeping/foundation/commands/audit-envelope.ts index fdf08dfb..4a66db80 100644 --- a/src/features/housekeeping/foundation/commands/audit-envelope.ts +++ b/src/features/housekeeping/foundation/commands/audit-envelope.ts @@ -50,10 +50,14 @@ export async function runWithAuditIntent( 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;