fix(source-maps): retain primary failures through cleanup retries

This commit is contained in:
morluto committed 2026-10-25 08:25:17 +08:00
1 parent 42c16ba631
commit 760d9f6019
6 files changed
+207 -60

No files matched your search

+30 -16
View File
@@ -4,6 +4,7 @@ import { join } from "node:path";
import { fileURLToPath } from "node:url";
import type { ExecutionOptions } from "../../application/AnalysisProvider.js";
import { AnalysisError } from "../../domain/analysisErrorBase.js";
import { analysisErrorWithCleanupFailure } from "../../domain/analysisErrorCleanup.js";
import {
AnalysisCancelledError,
AnalysisOutputError,
@@ -62,9 +63,12 @@ export interface SourceMapDecoderDependencies {
}
export interface SourceMapCleanupOwner {
close(
previousError: string | null,
): Promise<ProviderCleanupError | undefined>;
close(): Promise<ProviderCleanupError | undefined>;
}
/** The caller retains retry authority independently of the returned error. */
export interface SourceMapCleanupRetention {
owner?: SourceMapCleanupOwner | undefined;
}
type CodecPhysicalObservation =
@@ -88,7 +92,6 @@ type CodecOutcome =
export class SourceMapCleanupFailure extends ProviderCleanupError {
constructor(
readonly cleanupOwner: SourceMapCleanupOwner,
resources: readonly string[],
diagnostics: Readonly<Record<string, JsonValue>>,
) {
@@ -102,6 +105,7 @@ export const runSourceMapCommand = async (
path: string,
options: ExecutionOptions | undefined,
dependencies: SourceMapDecoderDependencies,
retainedCleanup: SourceMapCleanupRetention,
decodeTimeoutMs: number = DEFAULT_WEB_SOURCE_MAP_DECODE_TIMEOUT_MS,
): Promise<Result<string, AnalysisError>> => {
try {
@@ -141,13 +145,26 @@ export const runSourceMapCommand = async (
command.dispose();
deadline.dispose();
}
const cleanup = await command.close(result.ok ? null : result.error.message);
if (cleanup !== undefined) return err(cleanup);
return result.ok && options?.signal?.aborted
? err(
new AnalysisCancelledError(OPERATION, { cause: options.signal.reason }),
)
: result;
const cleanup = await command.close();
const completed =
result.ok && options?.signal?.aborted
? err(
new AnalysisCancelledError(OPERATION, {
cause: options.signal.reason,
}),
)
: result;
if (cleanup === undefined) return completed;
retainedCleanup.owner = command;
return completed.ok
? err(cleanup)
: err(
analysisErrorWithCleanupFailure(
completed.error,
cleanup,
OPERATION,
).bindCleanupDependencies([cleanup], command),
);
};
class OwnedCodec implements SourceMapCleanupOwner {
@@ -471,9 +488,7 @@ class OwnedCodec implements SourceMapCleanupOwner {
];
}
async close(
previousError: string | null,
): Promise<ProviderCleanupError | undefined> {
async close(): Promise<ProviderCleanupError | undefined> {
const failures: string[] = [];
let processReleased = this.#supervisor === undefined;
if (this.#supervisor !== undefined) {
@@ -497,10 +512,9 @@ class OwnedCodec implements SourceMapCleanupOwner {
this.#cleanupAnchor = undefined;
return undefined;
}
const failure = new SourceMapCleanupFailure(this, this.cleanupResources, {
const failure = new SourceMapCleanupFailure(this.cleanupResources, {
map_path: this.path,
cleanup_failures: failures,
previous_error: previousError,
codec_pid: this.#supervisor?.launch.process.pid ?? null,
}).bindCleanupResourceOwner(this);
if (this.#cleanupAnchor === undefined) this.#cleanupAnchor = failure;