fix(housekeeping): preserve pathological operation errors
This commit is contained in:
1 parent
b5957015e7
commit
86a2d9d069
2 files changed
+24
-4
No files matched your search
@@ -141,4 +141,24 @@ describe("audit command envelope", () => {
|
||||
runWithAuditIntent(writer, auditEntry, () => Promise.reject(original)),
|
||||
).rejects.toBe(original);
|
||||
});
|
||||
it("preserves a pathological rejection when failure evidence rejects", async () => {
|
||||
const { proxy, revoke } = Proxy.revocable(
|
||||
new Error("operation failed"),
|
||||
{},
|
||||
);
|
||||
revoke();
|
||||
const writer: HousekeepingAuditWriter = {
|
||||
write: vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(undefined)
|
||||
.mockRejectedValueOnce(new Error("audit failure")),
|
||||
};
|
||||
let rejected: unknown;
|
||||
try {
|
||||
await runWithAuditIntent(writer, auditEntry, () => Promise.reject(proxy));
|
||||
} catch (error) {
|
||||
rejected = error;
|
||||
}
|
||||
expect(rejected === proxy).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -49,15 +49,15 @@ export async function runWithAuditIntent<T>(
|
||||
try {
|
||||
await writeOutcome(writer, entry, "failure", transaction);
|
||||
} catch (auditOutcomeError) {
|
||||
if (error instanceof Error) {
|
||||
try {
|
||||
try {
|
||||
if (error instanceof Error) {
|
||||
Object.defineProperty(error, "auditOutcomeError", {
|
||||
value: auditOutcomeError,
|
||||
configurable: true,
|
||||
});
|
||||
} catch {
|
||||
// Frozen or non-extensible errors still preserve their original identity.
|
||||
}
|
||||
} catch {
|
||||
// Enrichment is best-effort; always preserve the original rejection.
|
||||
}
|
||||
}
|
||||
throw error;
|
||||
|
||||
Reference in new issue
Block a user