mirror of
https://github.com/morluto/rea.git
synced 2026-11-15 19:23:24 +00:00
* feat(artifacts): name integrity checks for DMG, directory and release-exposure readers Directory members and release-exposure members whose file identity or bytes changed since inventory report member-identity; a directory entry without captured state reports entry-metadata and a changed directory root container-identity; an hdiutil checksum failure reports image-checksum. AnalysisArtifactChangedError carries the check from the reader failure and projects it as details.integrity_check. * fix(artifacts): name missing directory entry state and keep integrity checks through error copies * feat(artifacts): name integrity checks for ZIP, PyInstaller and changed release files (#11081) feat(artifacts): name integrity checks for ZIP, PyInstaller and changed release files, and keep them through reader projections * feat(artifacts): name integrity checks for the remaining readers and their projections (#11098)
289 lines
9.6 KiB
TypeScript
289 lines
9.6 KiB
TypeScript
import { analysisErrorWithCancellation } from "../domain/analysisErrorCancellation.js";
|
|
import {
|
|
HopperRemoteError,
|
|
HopperTimeoutError,
|
|
HopperProcessError,
|
|
} from "../domain/hopperErrors.js";
|
|
import {
|
|
AnalysisError,
|
|
type AnalysisErrorOptions,
|
|
} from "../domain/analysisErrorBase.js";
|
|
import {
|
|
AnalysisCancelledError,
|
|
AnalysisCapabilityUnavailableError,
|
|
AnalysisAccessDeniedError,
|
|
AnalysisArtifactChangedError,
|
|
AnalysisResourceConstraintError,
|
|
reattributedResourceConstraint,
|
|
AnalysisOutputError,
|
|
AnalysisTimeoutError,
|
|
cancelledBy,
|
|
} from "../domain/analysisErrorCore.js";
|
|
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
|
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
|
|
import type { JsonValue } from "../domain/jsonValue.js";
|
|
import { ArtifactReaderFailure } from "../artifacts/ArtifactReader.js";
|
|
import { bindArtifactFileCleanup } from "../artifacts/ArtifactFileOperation.js";
|
|
|
|
/** Copy authored outcome facts; semantic attribution never inspects a later signal. */
|
|
export const analysisClientFailureContext = (
|
|
cause: AnalysisError,
|
|
providerId: string,
|
|
operation: string,
|
|
): AnalysisErrorOptions => {
|
|
const providerRequest =
|
|
cause instanceof HopperRemoteError ||
|
|
cause instanceof HopperTimeoutError ||
|
|
cause instanceof HopperProcessError
|
|
? {
|
|
...(cause.operation === undefined
|
|
? {}
|
|
: { operation: cause.operation }),
|
|
...(cause.requestId === undefined
|
|
? {}
|
|
: { request_id: cause.requestId }),
|
|
...(cause instanceof HopperRemoteError
|
|
? {
|
|
provider_code: cause.code,
|
|
diagnostic_type: cause.diagnosticType,
|
|
}
|
|
: {}),
|
|
}
|
|
: undefined;
|
|
const attribute = (
|
|
recorded: Readonly<Record<string, JsonValue>> | undefined,
|
|
): Readonly<Record<string, JsonValue>> | undefined =>
|
|
providerRequest === undefined
|
|
? recorded
|
|
: {
|
|
provider_request: providerRequest,
|
|
...(recorded === undefined ? {} : { provider_diagnostics: recorded }),
|
|
};
|
|
const diagnostics = attribute(cause.diagnostics);
|
|
const invocationDiagnostics =
|
|
cause.invocationDiagnostics === undefined
|
|
? undefined
|
|
: attribute(cause.invocationDiagnostics);
|
|
return {
|
|
cause,
|
|
...(cause.limit === undefined ? {} : { limit: cause.limit }),
|
|
...(cause.continuingCallerGuidance === undefined
|
|
? {}
|
|
: { continuingCallerGuidance: cause.continuingCallerGuidance }),
|
|
...(cause.cleanupPrimary === undefined
|
|
? {}
|
|
: {
|
|
cleanupPrimary: analysisClientFailureForOperation(
|
|
cause.cleanupPrimary,
|
|
providerId,
|
|
operation,
|
|
),
|
|
}),
|
|
...(cause.partialObservation === undefined
|
|
? {}
|
|
: { partialObservation: cause.partialObservation }),
|
|
...(cause.capturedOutput === undefined
|
|
? {}
|
|
: { capturedOutput: cause.capturedOutput }),
|
|
...(diagnostics === undefined ? {} : { diagnostics }),
|
|
...(invocationDiagnostics === undefined ? {} : { invocationDiagnostics }),
|
|
...(cause.cleanupIncomplete
|
|
? {
|
|
cleanup: {
|
|
reason: cause.cleanup?.reason ?? cause.message,
|
|
resources: cause.cleanupResources,
|
|
},
|
|
}
|
|
: {}),
|
|
};
|
|
};
|
|
|
|
/** Attribute producer-owned failure facts without inferring interruption. */
|
|
export const analysisClientFailureForOperation = (
|
|
cause: unknown,
|
|
providerId: string,
|
|
operation: string,
|
|
callerDiagnostics?: Readonly<Record<string, JsonValue>>,
|
|
): AnalysisError => {
|
|
if (!(cause instanceof AnalysisError)) {
|
|
const failure = new ProviderAdapterError(providerId, operation, {
|
|
cause,
|
|
...(callerDiagnostics === undefined
|
|
? {}
|
|
: { diagnostics: callerDiagnostics }),
|
|
...(cause instanceof ArtifactReaderFailure && cause.cleanup !== undefined
|
|
? { cleanup: cause.cleanup }
|
|
: {}),
|
|
});
|
|
bindArtifactFileCleanup(cause, failure);
|
|
return failure;
|
|
}
|
|
if (
|
|
!(cause instanceof HopperRemoteError) &&
|
|
!(cause instanceof HopperTimeoutError) &&
|
|
!(cause instanceof HopperProcessError) &&
|
|
!(cause instanceof AnalysisCancelledError) &&
|
|
!(cause instanceof ProviderAdapterError) &&
|
|
!(cause instanceof AnalysisCapabilityUnavailableError) &&
|
|
!(cause instanceof AnalysisAccessDeniedError) &&
|
|
!(cause instanceof AnalysisArtifactChangedError) &&
|
|
!(cause instanceof AnalysisTimeoutError) &&
|
|
!(cause instanceof AnalysisOutputError) &&
|
|
!(cause instanceof AnalysisResourceConstraintError)
|
|
)
|
|
return cause;
|
|
const sourceContext = analysisClientFailureContext(
|
|
cause,
|
|
providerId,
|
|
operation,
|
|
);
|
|
const context = {
|
|
...sourceContext,
|
|
...(callerDiagnostics === undefined
|
|
? {}
|
|
: {
|
|
diagnostics: { ...sourceContext.diagnostics, ...callerDiagnostics },
|
|
}),
|
|
};
|
|
let result: AnalysisError;
|
|
if (cause instanceof HopperRemoteError)
|
|
result = new HopperRemoteError(cause.code, cause.safeMessage, {
|
|
...context,
|
|
operation,
|
|
requestId: cause.requestId,
|
|
diagnosticType: cause.diagnosticType,
|
|
});
|
|
else if (cause instanceof HopperTimeoutError)
|
|
result = new HopperTimeoutError(
|
|
cause.timeoutMs,
|
|
operation,
|
|
cause.requestId,
|
|
cause.providerState,
|
|
cause.stage,
|
|
cause.launcherOutcome,
|
|
context,
|
|
);
|
|
else if (cause instanceof HopperProcessError)
|
|
result = new HopperProcessError(cause.exitCode, {
|
|
...context,
|
|
operation,
|
|
requestId: cause.requestId,
|
|
providerState: cause.providerState,
|
|
stage: cause.stage,
|
|
...(cause.diagnostic === undefined
|
|
? {}
|
|
: { diagnostic: cause.diagnostic }),
|
|
...(cause.launcherFailure === undefined
|
|
? {}
|
|
: { launcherFailure: cause.launcherFailure }),
|
|
});
|
|
else if (cause instanceof ProviderCleanupError) {
|
|
const { diagnostics, ...outcomeContext } = context;
|
|
result = new ProviderCleanupError(
|
|
cause.providerId,
|
|
cause.cleanupResources,
|
|
diagnostics ?? {},
|
|
{
|
|
...outcomeContext,
|
|
operation,
|
|
...(cause.completedObservation === undefined
|
|
? {}
|
|
: { completedObservation: cause.completedObservation }),
|
|
...(cause.remediationAction === undefined
|
|
? {}
|
|
: { remediationAction: cause.remediationAction }),
|
|
},
|
|
);
|
|
} else if (cause instanceof AnalysisTimeoutError)
|
|
result = new AnalysisTimeoutError(operation, cause.timeoutMs, {
|
|
...context,
|
|
...(cause.userMessage === undefined
|
|
? {}
|
|
: { userMessage: cause.userMessage }),
|
|
...(cause.remediationAction === undefined
|
|
? {}
|
|
: { remediationAction: cause.remediationAction }),
|
|
...(cause.limit === undefined ? {} : { limit: cause.limit }),
|
|
});
|
|
else if (cause instanceof AnalysisOutputError)
|
|
result = new AnalysisOutputError(operation, cause.reason, {
|
|
...context,
|
|
cleanupOnly: cause.cleanupOnly,
|
|
...(cause.userMessage === undefined
|
|
? {}
|
|
: { userMessage: cause.userMessage }),
|
|
...(cause.remediationAction === undefined
|
|
? {}
|
|
: { remediationAction: cause.remediationAction }),
|
|
});
|
|
else if (cause instanceof AnalysisCancelledError) {
|
|
const { cause: _wrapped, ...cancellationContext } = context;
|
|
result = cancelledBy(operation, cause, cancellationContext);
|
|
} else if (cause instanceof AnalysisCapabilityUnavailableError)
|
|
result = new AnalysisCapabilityUnavailableError(
|
|
cause.providerId,
|
|
operation,
|
|
cause.reason,
|
|
{
|
|
...context,
|
|
...(cause.userMessage === undefined
|
|
? {}
|
|
: { userMessage: cause.userMessage }),
|
|
...(cause.remediationAction === undefined
|
|
? {}
|
|
: { remediationAction: cause.remediationAction }),
|
|
...(cause.fallbackRemediationAction === undefined
|
|
? {}
|
|
: { fallbackRemediationAction: cause.fallbackRemediationAction }),
|
|
...(cause.siblingOperations === undefined
|
|
? {}
|
|
: { siblingOperations: cause.siblingOperations }),
|
|
...(cause.siblingReasons === undefined
|
|
? {}
|
|
: { siblingReasons: cause.siblingReasons }),
|
|
retryable: cause.retryable,
|
|
},
|
|
);
|
|
else if (cause instanceof AnalysisAccessDeniedError)
|
|
result = new AnalysisAccessDeniedError(
|
|
operation,
|
|
cause.path,
|
|
cause.systemCode,
|
|
context,
|
|
);
|
|
else if (cause instanceof AnalysisArtifactChangedError)
|
|
result = new AnalysisArtifactChangedError(
|
|
operation,
|
|
cause.path,
|
|
cause.reason,
|
|
{ ...context, integrityCheck: cause.integrityCheck },
|
|
);
|
|
else if (cause instanceof AnalysisResourceConstraintError)
|
|
result = reattributedResourceConstraint(operation, cause, context);
|
|
else
|
|
result = new ProviderAdapterError(providerId, operation, {
|
|
...context,
|
|
...(cause.userMessage === undefined
|
|
? {}
|
|
: { userMessage: cause.userMessage }),
|
|
...(cause.remediationAction === undefined
|
|
? {}
|
|
: { remediationAction: cause.remediationAction }),
|
|
});
|
|
for (const secondary of cause.secondaryFailures) {
|
|
if (secondary instanceof AnalysisCancelledError)
|
|
result = analysisErrorWithCancellation(result, secondary);
|
|
else result.retainSecondaryFailure(secondary);
|
|
}
|
|
// The attributed error reads its source's cleanup: live resources while it
|
|
// is pending, otherwise the source's completed release with the resources
|
|
// kept as history.
|
|
return cause.cleanupIncomplete
|
|
? result.bindCleanupDependencies([cause])
|
|
: result.bindCleanupReleaseClaim({
|
|
get cleanupReleased() {
|
|
return !cause.cleanupIncomplete;
|
|
},
|
|
});
|
|
};
|