Files
reverse-engineering-anything/scripts/lib/verifier-cleanup.mjs
T
morluto add15d65b3 refactor(verify): give verifier fixture roots one lease on src/process (#10988)
* refactor(verify): give verifier fixture roots one lease on src/process

* fix(verify): keep fixture registration closed, carry the lease on the caught failure, share cleanups once
2026-11-15 18:02:28 +08:00

39 lines
1008 B
JavaScript

async function collectCleanupFailures(tasks) {
const failures = [];
for (const task of tasks) {
try {
await task();
} catch (cause) {
failures.push(cause);
}
}
return failures;
}
/** Attempt every independent cleanup and preserve each failure. */
export async function closeVerifierResources(tasks) {
const failures = await collectCleanupFailures(tasks);
if (failures.length > 0)
throw new AggregateError(failures, "Verifier cleanup failed");
}
/** Finish one operation and its cleanup without losing either failure. */
export async function withVerifierCleanup(operation, cleanupTasks) {
let value;
try {
value = await operation();
} catch (cause) {
const failures = await collectCleanupFailures(cleanupTasks);
if (failures.length > 0)
throw new AggregateError(
[cause, ...failures],
"Verifier cleanup failed",
{ cause },
);
throw cause;
}
await closeVerifierResources(cleanupTasks);
return value;
}