Files
rea/src/domain/analysisErrorCleanup.ts
T
morluto 3ed925e547 fix(errors): exclude recovered cleanup resources
Compose only unresolved primary resources into a later cleanup failure, retaining both original causes and diagnostics. Document exact-owner recovery and cover resolved and unresolved composition controls. Refs #4266, #4274.
2026-10-16 09:06:13 +08:00

45 lines
1.5 KiB
TypeScript

import { ProviderAdapterError } from "./providerAdapterError.js";
import { projectAnalysisError } from "./analysisErrorProjection.js";
import type { AnalysisError } from "./analysisErrorBase.js";
/** Preserve the original lifecycle failure alongside incomplete cleanup. */
export const analysisErrorWithCleanupFailure = (
primary: AnalysisError,
cleanup: AnalysisError,
operation = "close_binary",
): AnalysisError => {
const projected = projectAnalysisError(cleanup);
return new ProviderAdapterError(
cleanup instanceof ProviderAdapterError ? cleanup.providerId : "rea",
operation,
{
cause: new AggregateError(
[primary, cleanup],
"Analysis failed and cleanup remains incomplete.",
{ cause: primary },
),
userMessage: projectAnalysisError(primary).message,
remediationAction: projected.remediation.action,
...(primary.capturedOutput === undefined
? {}
: { capturedOutput: primary.capturedOutput }),
...(primary.partialObservation === undefined
? {}
: { partialObservation: primary.partialObservation }),
cleanup: {
reason: projected.message,
resources: [
...new Set([
...(primary.cleanupIncomplete ? primary.cleanupResources : []),
...cleanup.cleanupResources,
]),
],
},
diagnostics: {
primary_error: projectAnalysisError(primary),
cleanup_error: projected,
},
},
);
};