mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 05:51:06 +00:00
refactor(resources): share artifact cleanup errors with their leases (#14606)
This commit is contained in:
1 parent
bfa50774f5
commit
b16df9d6c7
8 files changed
+49
-76
No files matched your search
@@ -5,11 +5,9 @@ import {
|
||||
} from "../providers/OwnedCommandCleanup.js";
|
||||
import { runWithExecutionLimits } from "./PlaywrightElectronExecution.js";
|
||||
import {
|
||||
ArtifactReaderFailure,
|
||||
bindArtifactFileCleanup,
|
||||
artifactFileCleanupError,
|
||||
ArtifactResourceScope,
|
||||
} from "../resources/index.js";
|
||||
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
|
||||
import { ElectronCaptureCleanup } from "./ElectronCaptureCleanup.js";
|
||||
import { analysisErrorWithCleanupDependencies } from "../domain/analysisErrorCleanup.js";
|
||||
import { analysisErrorWithCancellation } from "../domain/analysisErrorCancellation.js";
|
||||
@@ -584,16 +582,12 @@ const containLaunchRejections = async <T>(
|
||||
|
||||
const providerError = (cause: unknown): AnalysisError => {
|
||||
if (cause instanceof AnalysisError) return cause;
|
||||
if (cause instanceof ArtifactReaderFailure && cause.cleanup !== undefined) {
|
||||
const failure = new ProviderCleanupError(
|
||||
PLAYWRIGHT_ELECTRON_ACTIVE_PROVIDER_IDENTITY.id,
|
||||
cause.cleanup.resources,
|
||||
{ reason: cause.cleanup.reason },
|
||||
{ operation: OPERATION, cause },
|
||||
);
|
||||
bindArtifactFileCleanup(cause, failure);
|
||||
return failure;
|
||||
}
|
||||
const fileCleanup = artifactFileCleanupError(
|
||||
cause,
|
||||
PLAYWRIGHT_ELECTRON_ACTIVE_PROVIDER_IDENTITY.id,
|
||||
OPERATION,
|
||||
);
|
||||
if (fileCleanup !== undefined) return fileCleanup;
|
||||
return new ProviderAdapterError(
|
||||
PLAYWRIGHT_ELECTRON_ACTIVE_PROVIDER_IDENTITY.id,
|
||||
OPERATION,
|
||||
|
||||
@@ -3,11 +3,11 @@ import type { WebArtifactAcquisition as Acquisition } from "../../domain/webArti
|
||||
import { isAbortOf } from "../../process/SignalAbort.js";
|
||||
import { z } from "zod";
|
||||
import {
|
||||
artifactFileCleanupError,
|
||||
ArtifactReaderFailure,
|
||||
stableArtifactInputRecovery,
|
||||
artifactFileCancellationError,
|
||||
artifactFilePrimaryFacts,
|
||||
bindArtifactFileCleanup,
|
||||
type ArtifactFilePrimaryFacts,
|
||||
type ArtifactResourceScope,
|
||||
completedStableArtifact,
|
||||
@@ -27,7 +27,6 @@ import {
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
import { ArtifactOperationError } from "../../domain/artifactOperationError.js";
|
||||
import { ProviderAdapterError } from "../../domain/providerAdapterError.js";
|
||||
import { ProviderCleanupError } from "../../domain/providerCleanupError.js";
|
||||
import { analysisErrorWithCleanupDependencies } from "../../domain/analysisErrorCleanup.js";
|
||||
import { safeParseJson } from "../../domain/safeJson.js";
|
||||
import {
|
||||
@@ -152,14 +151,12 @@ export const webArtifactReadError = (
|
||||
context,
|
||||
signal,
|
||||
);
|
||||
if (cause instanceof ArtifactReaderFailure && cause.cleanup !== undefined) {
|
||||
const cleanup = new ProviderCleanupError(
|
||||
"captured-web-artifacts",
|
||||
cause.cleanup.resources,
|
||||
{ reason: cause.cleanup.reason },
|
||||
{ cause, operation: context.operation },
|
||||
);
|
||||
bindArtifactFileCleanup(cause, cleanup);
|
||||
const cleanup = artifactFileCleanupError(
|
||||
cause,
|
||||
"captured-web-artifacts",
|
||||
context.operation,
|
||||
);
|
||||
if (cleanup !== undefined) {
|
||||
return analysisErrorWithCleanupDependencies(
|
||||
primary,
|
||||
cleanup,
|
||||
|
||||
@@ -5,16 +5,15 @@ import {
|
||||
} from "../domain/analysisErrorCleanup.js";
|
||||
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
||||
import {
|
||||
artifactFileCleanupError,
|
||||
ArtifactResourceScope,
|
||||
ArtifactReaderFailure,
|
||||
withArtifactRegularFile,
|
||||
ArtifactFileCleanupFailure,
|
||||
artifactFileCompletion,
|
||||
bindArtifactFileCleanup,
|
||||
artifactFileCancellationError,
|
||||
assertArtifactReadActive,
|
||||
} from "../resources/index.js";
|
||||
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
|
||||
import { isUtf8 } from "node:buffer";
|
||||
import {
|
||||
AnalysisCapabilityUnavailableError,
|
||||
@@ -1314,14 +1313,8 @@ const discoveryFailure = (
|
||||
);
|
||||
}
|
||||
if (!(cause instanceof ArtifactReaderFailure)) return cause;
|
||||
if (cause.cleanup !== undefined) {
|
||||
const cleanup = new ProviderCleanupError(
|
||||
"cutter",
|
||||
cause.cleanup.resources,
|
||||
{ reason: cause.cleanup.reason },
|
||||
{ operation, cause },
|
||||
);
|
||||
bindArtifactFileCleanup(cause, cleanup);
|
||||
const cleanup = artifactFileCleanupError(cause, "cutter", operation);
|
||||
if (cleanup !== undefined) {
|
||||
const outcome =
|
||||
cause instanceof ArtifactFileCleanupFailure
|
||||
? cause.fileCleanupFailure.outcome
|
||||
|
||||
@@ -4,13 +4,12 @@ import {
|
||||
} from "../domain/parseFailureAnalysisError.js";
|
||||
import { ELECTRON_FUSE_PROVIDER_IDENTITY } from "./ElectronFuseProviderIdentity.js";
|
||||
import {
|
||||
artifactFileCleanupError,
|
||||
ArtifactReaderFailure,
|
||||
ArtifactFileCleanupFailure,
|
||||
artifactFileCompletion,
|
||||
artifactFileCancellationError,
|
||||
bindArtifactFileCleanup,
|
||||
} from "../resources/index.js";
|
||||
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
|
||||
import { analysisErrorWithCleanupDependencies } from "../domain/analysisErrorCleanup.js";
|
||||
import { regularFileCancellation } from "../filesystem/OwnedRegularFile.js";
|
||||
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
@@ -42,14 +41,12 @@ export const electronFuseFailure = (
|
||||
operation = OPERATION,
|
||||
): AnalysisError => {
|
||||
if (cause instanceof AnalysisError) return cause;
|
||||
if (cause instanceof ArtifactReaderFailure && cause.cleanup !== undefined) {
|
||||
const cleanup = new ProviderCleanupError(
|
||||
ELECTRON_FUSE_PROVIDER_IDENTITY.id,
|
||||
cause.cleanup.resources,
|
||||
{ reason: cause.cleanup.reason },
|
||||
{ operation, cause },
|
||||
);
|
||||
bindArtifactFileCleanup(cause, cleanup);
|
||||
const cleanup = artifactFileCleanupError(
|
||||
cause,
|
||||
ELECTRON_FUSE_PROVIDER_IDENTITY.id,
|
||||
operation,
|
||||
);
|
||||
if (cleanup !== undefined) {
|
||||
if (cause instanceof ArtifactFileCleanupFailure) {
|
||||
const outcome = cause.fileCleanupFailure.outcome;
|
||||
const cancellation = artifactFileCompletion(cause)?.cancellation;
|
||||
|
||||
@@ -11,9 +11,8 @@ import {
|
||||
} from "../../domain/javascript/javascriptSemanticWorkAllowance.js";
|
||||
import { MAX_NODE_TIMER_DELAY_MS } from "../../domain/analysisResourceLimits.js";
|
||||
import {
|
||||
artifactFileCleanupError,
|
||||
ArtifactResourceScope,
|
||||
ArtifactReaderFailure,
|
||||
bindArtifactFileCleanup,
|
||||
} from "../../resources/index.js";
|
||||
import { analysisErrorWithCleanupDependencies } from "../../domain/analysisErrorCleanup.js";
|
||||
import {
|
||||
@@ -1443,16 +1442,8 @@ export class JavaScriptAnalysisWorker {
|
||||
: cancellation.capturedOutput === undefined
|
||||
? cancellation.retainCapturedOutput(this.#captured())
|
||||
: cancellation;
|
||||
if (cause instanceof ArtifactReaderFailure && cause.cleanup !== undefined) {
|
||||
const error = new ProviderCleanupError(
|
||||
PROVIDER,
|
||||
cause.cleanup.resources,
|
||||
{ reason: cause.cleanup.reason },
|
||||
{ operation: OPERATION, cause },
|
||||
);
|
||||
bindArtifactFileCleanup(cause, error);
|
||||
return error;
|
||||
}
|
||||
const fileCleanup = artifactFileCleanupError(cause, PROVIDER, OPERATION);
|
||||
if (fileCleanup !== undefined) return fileCleanup;
|
||||
if (
|
||||
cause instanceof AnalysisError &&
|
||||
(deadline === undefined || this.#phase === "startup")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
artifactFileCleanupError,
|
||||
ArtifactFileCleanupFailure,
|
||||
artifactFilePrimaryFacts,
|
||||
bindArtifactFileCleanup,
|
||||
@@ -354,19 +355,12 @@ export class KunaTargetCommands {
|
||||
try {
|
||||
return await this.#resources.run(work);
|
||||
} catch (cause: unknown) {
|
||||
if (
|
||||
cause instanceof ArtifactReaderFailure &&
|
||||
cause.cleanup !== undefined
|
||||
) {
|
||||
const failure = new ProviderCleanupError(
|
||||
KUNA_PROVIDER_ID,
|
||||
cause.cleanup.resources,
|
||||
{ reason: cause.cleanup.reason },
|
||||
{ cause, operation },
|
||||
);
|
||||
bindArtifactFileCleanup(cause, failure);
|
||||
return err(failure);
|
||||
}
|
||||
const fileCleanup = artifactFileCleanupError(
|
||||
cause,
|
||||
KUNA_PROVIDER_ID,
|
||||
operation,
|
||||
);
|
||||
if (fileCleanup !== undefined) return err(fileCleanup);
|
||||
if (this.#closing && cause instanceof ArtifactReaderFailure)
|
||||
return err(cancelledBy(operation, carriedReason(cause)));
|
||||
throw cause;
|
||||
|
||||
@@ -215,18 +215,24 @@ const artifactCleanupFailure = (
|
||||
);
|
||||
};
|
||||
|
||||
/** Project descriptor cleanup while keeping its exact leases bound to the error. */
|
||||
/** Build the provider cleanup error and bind it to the reader's exact leases. */
|
||||
export const artifactFileCleanupError = (
|
||||
cause: unknown,
|
||||
providerId: string,
|
||||
operation: string,
|
||||
): ProviderCleanupError | undefined => {
|
||||
if (!(cause instanceof ArtifactReaderFailure)) return undefined;
|
||||
const error = artifactCleanupFailure(cause, providerId, operation);
|
||||
if (error !== undefined) bindArtifactFileCleanup(cause, error);
|
||||
return error;
|
||||
};
|
||||
|
||||
/** Preserve the original close failure when the reader has no cleanup evidence. */
|
||||
export const projectArtifactCloseFailure = (
|
||||
cause: unknown,
|
||||
providerId: string,
|
||||
operation: string,
|
||||
): unknown => {
|
||||
if (!(cause instanceof ArtifactReaderFailure)) return cause;
|
||||
const error = artifactCleanupFailure(cause, providerId, operation);
|
||||
if (error === undefined) return cause;
|
||||
bindArtifactFileCleanup(cause, error);
|
||||
return error;
|
||||
};
|
||||
): unknown => artifactFileCleanupError(cause, providerId, operation) ?? cause;
|
||||
|
||||
/** Close a provider's descriptor scope and preserve its cleanup leases on failure. */
|
||||
export const closeArtifactResources = async (
|
||||
|
||||
@@ -100,6 +100,7 @@ export type {
|
||||
export {
|
||||
imageFileSizeRemediation,
|
||||
closeArtifactResources,
|
||||
artifactFileCleanupError,
|
||||
projectArtifactCloseFailure,
|
||||
withArtifactCleanupFailure,
|
||||
artifactFileCancellationError,
|
||||
|
||||
Reference in new issue
Block a user