mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 14:59:05 +00:00
* fix(errors)!: derive retryable from the producer's declared retry class `retryable` means the unchanged request may succeed, but it was computed downstream as an OR of a code table and five class rules. Every error classification now declares a retry class (same_call, change_first, never, unknown_outcome); `retryable` is `same_call` after one incomplete-cleanup check, and the RETRYABLE_CODES table is deleted. Producer corrections: - update_unknown revision conflicts are change_first and report details.current_revision; duplicate record_unknown reports details.existing_unknown_id. - close_gdb_session's explicit-disposition refusal is change_first. - Per-call artifact reader limits are change_first (never when the limit cannot rise). - An exited or unreachable Hopper bridge, and a Hopper start that another REA session owns, are change_first. - File-descriptor exhaustion (EMFILE/ENFILE) outside process launch is occupied host capacity (same_call) for private workspaces, model and GPU readers and JavaScript application reads. - apktool JVM native-thread exhaustion follows the shared capacity default. BREAKING CHANGE: these refusals now report `retryable: false` (descriptor pressure now reports `retryable: true` as `resource_constraint`). Callers that repeated them unchanged should follow the remediation first: re-read the unknown and retry with details.current_revision, dispose GDB inferiors, raise the reported reader limit, or restart the Hopper provider. * fix(errors): require producers to name recovery for conforming refusals A refusal whose arguments match the input schema was presented as a schema error whenever its producer left out remediation, and many producers did. AnalysisInputError's options are now a union: a conforming refusal must supply both its outcome (userMessage) and next step (remediationAction), so the compiler lists every producer; only contract violations may fall back to the schema guidance. Producers fixed: unknown Frida session and script, decompile_all output-directory state, the duplicate unknown build computer factory (collapsed), stale Cutter sessions, Mach-O architecture selection, output roots that already exist, selected files the host refuses, Ghidra lookups the bridge could not resolve, YARA path refusals, unresolved native symbol names, apt key files and withheld sign-in state. A missing selected APK is now target_unavailable like every other selected-file reader. The capability fallback "Choose another analysis or target" is deleted; a capability refusal without its own recovery names details.reason and binary_session. Refs #15312 * fix(errors): classify caller selections and target bytes by their real failure Several refusals reported a code that reads as corruption or a crash: - a missing unknown_id and a missing Evidence reference now report invalid_request instead of execution_failure and evidence_integrity_mismatch; - close_binary with snapshot_path in a resource-only session reports invalid_request instead of evidence_integrity_mismatch; - ADB push onto an existing device path and pulls into an occupied output directory are conforming invalid_request refusals naming overwrite or output_directory, not unreadable_output; - damaged APK ZIP, signing-block, signer and central-directory structures are malformed targets, not invalid input; - NuGet and VSIX bytes without a ZIP signature are unrecognized, not malformed; - a historical source graph file whose entries contradict its root commitment is an integrity failure, not invalid input; - a CDP protocol failure states what happened instead of the unclassified fallback message. Refs #15319 * feat(errors): expose the producer's retry class as retry_class Every error projection now carries retry_class (same_call, change_first, never or unknown_outcome) beside retryable, which stays true exactly for same_call. The field is additive: the error schema accepts errors retained by earlier releases without it. Refs #15323 * fix(errors): address review of the folded error-contract PRs Keep a provider's own capability message as its remediation; the binary_session fallback applies only to a bare declared reason. Delete the unused conformingInputRefusal helper. Compose both retry fields for a refused publication whose cleanup is incomplete. Report descriptor exhaustion from a JavaScript directory opendir as occupied capacity. Let an exited Hopper startup attempt without a setup failure code retry unchanged. Declare retry for the Ghidra superseded checkpoint and unknown IDA readiness. Redact ambiguous selector candidates. Give a Ghidra document miss its own recovery. Drop an unchanged-files claim the journal repair cannot make. Name each withheld sign-in refusal's step. Hash the source graph commitment before the cancellation yield. Keep the browser protocol_error message neutral. Add tests for mutation-audit survivors C3, C5, P2, P4, P8, H1, H4 and H5. * fix(errors): keep a missing Evidence reference an integrity failure and state only the observed commitment mismatch * test(desktop): assert the unknown build computer refusal's remediation, not its message The refusal now carries its next step in remediation.action instead of the message, so the closed-computer checks assert the exact code, message and remediation facts. * fix(errors): keep producer retry choices apart from cleanup and fixed ceilings A capture's retryable flag no longer folds in pending cleanup, so the projection applies the cleanup rule once and a transient capture with pending cleanup reports change_first instead of never. A release-fixed artifact allowance reports never, and a stale admitted session identity reports change_first (reopen, then retry); both have catalogue rows. The bare capability-unavailable remediation names binary_session only for a binary-analysis session, so standalone bridges such as Cutter are pointed at their own reason. * test(vsix): expect a non-ZIP selection to be refused as unrecognized This PR reports bytes without a ZIP signature as another format (unrecognized), not a damaged package; the exact-reason assertion added on main still expected malformed. * test(delivery): expect the capacity refusal's retry class in delivered failure facts The exact failure facts asserted on main predate the projection's retry_class; occupied capacity reports same_call. * fix(errors): mark a sent Hopper cancellation unknown and missing Evidence recoverable A cancellation Hopper already received may still apply, so its retry class is unknown_outcome instead of same_call; an unsent cancellation keeps same_call. A missing EvidenceReferenceError is change_first, since importing the referenced records lets the same request succeed; other reference failures stay never. Both have catalogue rows. * fix(hopper): ask for changed launch arguments before retrying an unencodable launch A launcher path or argument that cannot be encoded as an AppleScript literal meets the same pre-launch guard on every attempt, so the start refusal is change_first and its retry_action is unknown; a start failure without a declared reason stays same_call. * fix(errors): keep a one-shot cleanup failure's retry class with its cleanup state A one-shot reply that reports cleanup_incomplete spread the primary or cleanup projection and overrode only retryable, so a timed-out read whose close also failed carried retry_class same_call. The reply now reads its retry class from the typed composed failure, and never offers the same call before cleanup settles. * test(evtx): expect an unreadable selected log to be refused with its own recovery This PR treats a well-formed path the host refused as a regular file as conforming input with its own remediation; the evtx boundary test still expected a schema-recovery refusal. * test(javascript): expect a broken source-graph commitment as an integrity failure This PR reports a well-formed historical source graph whose entries disagree with its root_sha256 as evidence_integrity_mismatch, not an input issue; the exact refusal assertion added on main still expected invalid_request.
726 lines
22 KiB
TypeScript
726 lines
22 KiB
TypeScript
import {
|
|
AnalysisCapabilityUnavailableError,
|
|
AnalysisResourceConstraintError,
|
|
AnalysisTargetFailureError,
|
|
} from "./analysisErrorCore.js";
|
|
import {
|
|
TARGET_FAILURE_KINDS,
|
|
TARGET_FAILURE_PROJECTIONS,
|
|
targetFailureRetry,
|
|
type TargetFailureKind,
|
|
type TargetFailureRetry,
|
|
} from "./targetFailure.js";
|
|
import {
|
|
domainErrorTag,
|
|
type AnalysisError,
|
|
type AnalysisErrorTag,
|
|
type ProviderErrorTag,
|
|
} from "./analysisErrorBase.js";
|
|
import type { AnalysisErrorProjection } from "./analysisErrorProjection.js";
|
|
import {
|
|
ArtifactOperationError,
|
|
integrityCheckMeansChanged,
|
|
} from "./artifactOperationError.js";
|
|
import { BrowserObservationError } from "./browserObservationError.js";
|
|
import type { BrowserObservationFailureReason } from "./browserObservationErrors.js";
|
|
import {
|
|
BinaryTargetError,
|
|
type BinaryTargetErrorOptions,
|
|
} from "./configurationErrors.js";
|
|
import {
|
|
EvidenceFileError,
|
|
EvidenceReferenceError,
|
|
ResourceSnapshotMismatchError,
|
|
} from "./evidenceErrors.js";
|
|
import {
|
|
ProviderSelectionError,
|
|
type ProviderSelectionFailureReason,
|
|
} from "./providerSelectionError.js";
|
|
import { UnknownRegistryError } from "./unknownRegistryError.js";
|
|
|
|
type ErrorCode = AnalysisErrorProjection["code"];
|
|
type ErrorCategory = AnalysisErrorProjection["category"];
|
|
|
|
/**
|
|
* What the caller must do before the failed request can succeed. Only the
|
|
* failure's producer knows this, so every classification declares it:
|
|
* - `same_call`: the unchanged request may succeed later (a transient fault,
|
|
* occupied capacity, a cancellation or a deadline).
|
|
* - `change_first`: the caller must change the request or the state it reads
|
|
* first (re-read a revision, raise a limit, settle a disposition).
|
|
* - `never`: no change the caller can make to this request clears it.
|
|
* - `unknown_outcome`: the request may have taken effect; reconcile the
|
|
* resulting state before deciding to repeat it.
|
|
*/
|
|
export type AnalysisRetryClass =
|
|
| "same_call"
|
|
| "change_first"
|
|
| "never"
|
|
| "unknown_outcome";
|
|
|
|
/** The caller-facing code, category and retry class of one error case. */
|
|
export interface AnalysisErrorClassification {
|
|
readonly code: ErrorCode;
|
|
readonly category: ErrorCategory;
|
|
readonly retry: AnalysisRetryClass;
|
|
}
|
|
|
|
/** A target failure kind's public retry hint, as the shared retry class. */
|
|
const TARGET_FAILURE_RETRY_CLASSES = {
|
|
backoff: "same_call",
|
|
after_change: "change_first",
|
|
none: "never",
|
|
} as const satisfies Readonly<Record<TargetFailureRetry, AnalysisRetryClass>>;
|
|
|
|
/** Domain tags whose classification depends on the error's own facts. */
|
|
type SpecializedErrorTag =
|
|
| "AnalysisTargetFailureError"
|
|
| "ArtifactOperationError"
|
|
| "BinaryTargetError"
|
|
| "BrowserObservationError"
|
|
| "EvidenceFileError"
|
|
| "ProcessCaptureError"
|
|
| "ProviderSelectionError"
|
|
| "UnknownRegistryError";
|
|
|
|
const classified = (
|
|
code: ErrorCode,
|
|
category: ErrorCategory,
|
|
retry: AnalysisRetryClass,
|
|
): AnalysisErrorClassification => ({ code, category, retry });
|
|
|
|
const STATIC_ERROR_CLASSIFICATIONS = {
|
|
AnalysisProtocolError: classified(
|
|
"unreadable_output",
|
|
"execution_failure",
|
|
"never",
|
|
),
|
|
AnalysisOutputError: classified(
|
|
"unreadable_output",
|
|
"execution_failure",
|
|
"never",
|
|
),
|
|
AnalysisInputError: classified(
|
|
"invalid_request",
|
|
"invalid_input",
|
|
"change_first",
|
|
),
|
|
AnalysisAccessDeniedError: classified(
|
|
"access_denied",
|
|
"unavailable",
|
|
"change_first",
|
|
),
|
|
AnalysisArtifactChangedError: classified(
|
|
"artifact_changed",
|
|
"integrity_mismatch",
|
|
"same_call",
|
|
),
|
|
AnalysisCapabilityUnavailableError: classified(
|
|
"capability_unavailable",
|
|
"unsupported_provider",
|
|
"never",
|
|
),
|
|
AnalysisCancelledError: classified("cancelled", "cancelled", "same_call"),
|
|
AnalysisTimeoutError: classified("provider_timeout", "timeout", "same_call"),
|
|
AnalysisResourceConstraintError: classified(
|
|
"resource_constraint",
|
|
"resource_constraint",
|
|
"change_first",
|
|
),
|
|
ConfigurationError: classified(
|
|
"configuration_invalid",
|
|
"invalid_input",
|
|
"change_first",
|
|
),
|
|
NoBinaryOpenError: classified(
|
|
"target_unavailable",
|
|
"unavailable",
|
|
"change_first",
|
|
),
|
|
EvidenceIntegrityError: classified(
|
|
"evidence_integrity_mismatch",
|
|
"integrity_mismatch",
|
|
"never",
|
|
),
|
|
ProviderAdapterError: classified(
|
|
"execution_failure",
|
|
"execution_failure",
|
|
"never",
|
|
),
|
|
} as const satisfies Readonly<
|
|
Record<
|
|
Exclude<AnalysisErrorTag, SpecializedErrorTag>,
|
|
AnalysisErrorClassification
|
|
>
|
|
>;
|
|
|
|
/**
|
|
* A capability the caller may wait for, or make available, is unavailable,
|
|
* not unsupported. Its producer says which.
|
|
*/
|
|
const availableLaterCapability = (
|
|
retry: "same_call" | "change_first",
|
|
): AnalysisErrorClassification =>
|
|
classified("capability_unavailable", "unavailable", retry);
|
|
|
|
/** The classification the projection table gives one target failure kind. */
|
|
const kindClassification = (
|
|
kind: TargetFailureKind,
|
|
): AnalysisErrorClassification => {
|
|
const { code, category, retry } = TARGET_FAILURE_PROJECTIONS[kind];
|
|
return { code, category, retry: TARGET_FAILURE_RETRY_CLASSES[retry] };
|
|
};
|
|
|
|
const ARTIFACT_OPERATION_CLASSIFICATIONS = {
|
|
cancelled: classified("cancelled", "cancelled", "same_call"),
|
|
// `limit` reports `partial`: the result was cut short.
|
|
integrity: classified(
|
|
"artifact_operation_failed",
|
|
"integrity_mismatch",
|
|
"never",
|
|
),
|
|
limit: classified("partial", "partial", "change_first"),
|
|
path: classified("artifact_operation_failed", "execution_failure", "never"),
|
|
unavailable: classified(
|
|
"artifact_operation_failed",
|
|
"unavailable",
|
|
"change_first",
|
|
),
|
|
io: classified("artifact_operation_failed", "execution_failure", "never"),
|
|
} as const satisfies Readonly<
|
|
Record<ArtifactOperationError["reason"], AnalysisErrorClassification>
|
|
>;
|
|
|
|
/** An integrity failure that names the artifact's expected and observed identity. */
|
|
const ARTIFACT_IDENTITY_MISMATCH = classified(
|
|
"artifact_integrity_mismatch",
|
|
"integrity_mismatch",
|
|
"never",
|
|
);
|
|
|
|
/**
|
|
* The session's opened target no longer matches its bytes: reopening the
|
|
* artifact, then retrying, recovers.
|
|
*/
|
|
const ARTIFACT_ADMITTED_IDENTITY_STALE = classified(
|
|
"artifact_operation_failed",
|
|
"integrity_mismatch",
|
|
"change_first",
|
|
);
|
|
|
|
const EVIDENCE_FILE_CLASSIFICATIONS = {
|
|
// A missing, non-file or already-existing path is the caller's selection.
|
|
"not-file": classified("invalid_request", "invalid_input", "change_first"),
|
|
exists: classified("invalid_request", "invalid_input", "change_first"),
|
|
"wrong-kind": classified("invalid_request", "invalid_input", "change_first"),
|
|
missing: classified("invalid_request", "invalid_input", "change_first"),
|
|
"symlink-traversal": classified(
|
|
"invalid_request",
|
|
"invalid_input",
|
|
"change_first",
|
|
),
|
|
"invalid-json": classified(
|
|
"evidence_integrity_mismatch",
|
|
"execution_failure",
|
|
"never",
|
|
),
|
|
"path-limit": classified(
|
|
"resource_constraint",
|
|
"resource_constraint",
|
|
"change_first",
|
|
),
|
|
"storage-limit": classified(
|
|
"resource_constraint",
|
|
"resource_constraint",
|
|
"change_first",
|
|
),
|
|
io: classified("execution_failure", "execution_failure", "never"),
|
|
} as const satisfies Readonly<
|
|
Record<EvidenceFileError["reason"], AnalysisErrorClassification>
|
|
>;
|
|
|
|
const UNKNOWN_REGISTRY_CLASSIFICATIONS = {
|
|
// An unknown_id this session does not hold is the caller's selection.
|
|
"not-found": classified("invalid_request", "invalid_input", "change_first"),
|
|
"already-exists": classified(
|
|
"invalid_request",
|
|
"invalid_input",
|
|
"change_first",
|
|
),
|
|
"revision-conflict": classified(
|
|
"revision_conflict",
|
|
"execution_failure",
|
|
"change_first",
|
|
),
|
|
"invalid-transition": classified(
|
|
"execution_failure",
|
|
"execution_failure",
|
|
"change_first",
|
|
),
|
|
integrity: classified(
|
|
"evidence_integrity_mismatch",
|
|
"execution_failure",
|
|
"never",
|
|
),
|
|
limit: classified("partial", "execution_failure", "change_first"),
|
|
constraint: classified("invalid_request", "invalid_input", "change_first"),
|
|
} as const satisfies Readonly<
|
|
Record<UnknownRegistryError["reason"], AnalysisErrorClassification>
|
|
>;
|
|
|
|
const PROVIDER_SELECTION_CLASSIFICATIONS = {
|
|
unknown_provider: classified(
|
|
"capability_unavailable",
|
|
"unsupported_provider",
|
|
"change_first",
|
|
),
|
|
provider_unavailable: classified(
|
|
"provider_unavailable",
|
|
"unavailable",
|
|
"same_call",
|
|
),
|
|
target_unsupported: classified(
|
|
"capability_unavailable",
|
|
"unsupported_provider",
|
|
"never",
|
|
),
|
|
ambiguous: classified(
|
|
"capability_unavailable",
|
|
"unsupported_provider",
|
|
"change_first",
|
|
),
|
|
invalid_options: classified(
|
|
"capability_unavailable",
|
|
"unsupported_provider",
|
|
"change_first",
|
|
),
|
|
} as const satisfies Readonly<
|
|
Record<ProviderSelectionFailureReason, AnalysisErrorClassification>
|
|
>;
|
|
|
|
type BinaryTargetConstraintKey =
|
|
| NonNullable<BinaryTargetErrorOptions["constraint"]>
|
|
| "unconstrained";
|
|
|
|
const BINARY_TARGET_CLASSIFICATIONS = {
|
|
unconstrained: classified(
|
|
"target_unavailable",
|
|
"unavailable",
|
|
"change_first",
|
|
),
|
|
directory_requires_file: classified(
|
|
"target_unavailable",
|
|
"unavailable",
|
|
"change_first",
|
|
),
|
|
wasm_requires_static_inspection: classified(
|
|
"target_unavailable",
|
|
"unsupported_target",
|
|
"change_first",
|
|
),
|
|
file_format_rejected: classified(
|
|
"target_unavailable",
|
|
"unsupported_target",
|
|
"change_first",
|
|
),
|
|
load_selection_rejected: classified(
|
|
"invalid_request",
|
|
"invalid_input",
|
|
"change_first",
|
|
),
|
|
bundle_type_unsupported: classified(
|
|
"target_unavailable",
|
|
"unsupported_target",
|
|
"change_first",
|
|
),
|
|
bundle_info_plist_decode_budget_exceeded: classified(
|
|
"target_unavailable",
|
|
"unavailable",
|
|
"change_first",
|
|
),
|
|
bundle_info_plist_missing: classified(
|
|
"target_unavailable",
|
|
"unavailable",
|
|
"change_first",
|
|
),
|
|
bundle_layout_ambiguous: classified(
|
|
"target_unavailable",
|
|
"unavailable",
|
|
"change_first",
|
|
),
|
|
bundle_executable_undeclared: classified(
|
|
"target_unavailable",
|
|
"unavailable",
|
|
"change_first",
|
|
),
|
|
bundle_program_missing: classified(
|
|
"target_unavailable",
|
|
"unavailable",
|
|
"change_first",
|
|
),
|
|
bundle_current_version_missing: classified(
|
|
"target_unavailable",
|
|
"unavailable",
|
|
"change_first",
|
|
),
|
|
bundle_path_escapes: classified(
|
|
"target_unavailable",
|
|
"unavailable",
|
|
"change_first",
|
|
),
|
|
} as const satisfies Readonly<
|
|
Record<BinaryTargetConstraintKey, AnalysisErrorClassification>
|
|
>;
|
|
|
|
/** A target the host refused to read keeps its constraint's category. */
|
|
const binaryTargetClassification = (
|
|
constraint: BinaryTargetConstraintKey,
|
|
readPermissionDenied: boolean,
|
|
): AnalysisErrorClassification => {
|
|
const base = BINARY_TARGET_CLASSIFICATIONS[constraint];
|
|
return readPermissionDenied && constraint !== "load_selection_rejected"
|
|
? { ...base, code: "access_denied" }
|
|
: base;
|
|
};
|
|
|
|
const BROWSER_OBSERVATION_CLASSIFICATIONS = {
|
|
endpoint_unreachable: classified(
|
|
"provider_unavailable",
|
|
"unavailable",
|
|
"same_call",
|
|
),
|
|
invalid_endpoint_response: classified(
|
|
"unreadable_output",
|
|
"execution_failure",
|
|
"never",
|
|
),
|
|
target_not_found: classified(
|
|
"target_unavailable",
|
|
"unavailable",
|
|
"change_first",
|
|
),
|
|
target_not_allowed: classified(
|
|
"target_unavailable",
|
|
"unavailable",
|
|
"change_first",
|
|
),
|
|
application_already_running: classified(
|
|
"target_unavailable",
|
|
"unavailable",
|
|
"change_first",
|
|
),
|
|
service_worker_blocked: classified(
|
|
"target_unavailable",
|
|
"unavailable",
|
|
"change_first",
|
|
),
|
|
target_changed: classified(
|
|
"target_unavailable",
|
|
"unavailable",
|
|
"change_first",
|
|
),
|
|
target_session_detached: classified(
|
|
"target_unavailable",
|
|
"unavailable",
|
|
"change_first",
|
|
),
|
|
protocol_error: classified("unreadable_output", "execution_failure", "never"),
|
|
disconnected: classified("provider_unavailable", "unavailable", "same_call"),
|
|
payload_limit: classified("partial", "partial", "change_first"),
|
|
window_not_found: classified(
|
|
"unreadable_output",
|
|
"execution_failure",
|
|
"never",
|
|
),
|
|
window_metadata_missing: classified(
|
|
"unreadable_output",
|
|
"execution_failure",
|
|
"never",
|
|
),
|
|
process_ownership_unavailable: classified(
|
|
"unreadable_output",
|
|
"execution_failure",
|
|
"never",
|
|
),
|
|
cleanup_failed: classified("execution_failure", "execution_failure", "never"),
|
|
cancelled: classified("cancelled", "cancelled", "same_call"),
|
|
timeout: classified("provider_timeout", "timeout", "same_call"),
|
|
} as const satisfies Readonly<
|
|
Record<BrowserObservationFailureReason, AnalysisErrorClassification>
|
|
>;
|
|
|
|
/**
|
|
* A snapshot path given to a resource-only session, which has no executable
|
|
* binding: the caller's selection, not changed or forged Evidence. A missing
|
|
* Evidence reference stays an integrity failure, because the same reason
|
|
* reports a retained source or closure member that the supplied Evidence
|
|
* itself should have held.
|
|
*/
|
|
const RESOURCE_SNAPSHOT_NOT_APPLICABLE = classified(
|
|
"invalid_request",
|
|
"invalid_input",
|
|
"change_first",
|
|
);
|
|
|
|
/**
|
|
* Referenced Evidence this session does not hold: importing the missing
|
|
* records lets the same request succeed.
|
|
*/
|
|
const EVIDENCE_REFERENCE_MISSING = classified(
|
|
"evidence_integrity_mismatch",
|
|
"integrity_mismatch",
|
|
"change_first",
|
|
);
|
|
|
|
/** Any error the caller's cancellation caused reports as that cancellation. */
|
|
const CANCELLED = classified("cancelled", "cancelled", "same_call");
|
|
|
|
const PROCESS_CAPTURE_FAILED = classified(
|
|
"process_capture_failed",
|
|
"execution_failure",
|
|
"never",
|
|
);
|
|
|
|
/** A tag whose code and category do not depend on the error's facts. */
|
|
const staticClassification = (
|
|
error: AnalysisError,
|
|
): AnalysisErrorClassification => {
|
|
const tag = domainErrorTag(error);
|
|
if (tag === undefined)
|
|
throw new TypeError(`Unpresented provider error: ${error._tag}`);
|
|
switch (tag) {
|
|
case "AnalysisTargetFailureError":
|
|
case "ArtifactOperationError":
|
|
case "BinaryTargetError":
|
|
case "BrowserObservationError":
|
|
case "EvidenceFileError":
|
|
case "ProcessCaptureError":
|
|
case "ProviderSelectionError":
|
|
case "UnknownRegistryError":
|
|
throw new TypeError(`Unhandled specialized analysis error: ${tag}`);
|
|
default:
|
|
return STATIC_ERROR_CLASSIFICATIONS[tag];
|
|
}
|
|
};
|
|
|
|
/**
|
|
* The code, category and retry class of a domain-presented error. A
|
|
* provider-owned error supplies its own through `ownPresentation()`. Cleanup
|
|
* state is applied by the projection, which reports `cleanup_incomplete`
|
|
* above this code.
|
|
*/
|
|
export const classifyAnalysisError = (
|
|
error: AnalysisError,
|
|
): AnalysisErrorClassification => {
|
|
const owned = error.ownPresentation();
|
|
if (owned !== undefined)
|
|
return { code: owned.code, category: owned.category, retry: owned.retry };
|
|
if (
|
|
error instanceof AnalysisCapabilityUnavailableError &&
|
|
error.retry !== "never"
|
|
)
|
|
return availableLaterCapability(error.retry);
|
|
if (error instanceof AnalysisTargetFailureError)
|
|
return {
|
|
...kindClassification(error.failure.kind),
|
|
retry: TARGET_FAILURE_RETRY_CLASSES[targetFailureRetry(error.failure)],
|
|
};
|
|
if (error instanceof ProviderSelectionError)
|
|
return PROVIDER_SELECTION_CLASSIFICATIONS[error.reason];
|
|
if (error instanceof BrowserObservationError)
|
|
return error.userCategory === "cancelled"
|
|
? CANCELLED
|
|
: BROWSER_OBSERVATION_CLASSIFICATIONS[error.reason];
|
|
if (error instanceof ArtifactOperationError) {
|
|
// A reader limit says whether the caller can raise it; a release-fixed
|
|
// allowance cannot change.
|
|
if (error.reason !== "integrity" && error.fixedAllowance !== undefined)
|
|
return {
|
|
...ARTIFACT_OPERATION_CLASSIFICATIONS[error.reason],
|
|
retry: "never",
|
|
};
|
|
if (error.readerLimit !== undefined && error.reason !== "integrity")
|
|
return {
|
|
...ARTIFACT_OPERATION_CLASSIFICATIONS[error.reason],
|
|
retry: error.readerLimit.can_increase ? "change_first" : "never",
|
|
};
|
|
if (error.reason !== "integrity")
|
|
return ARTIFACT_OPERATION_CLASSIFICATIONS[error.reason];
|
|
if (error.artifactDetails !== undefined) return ARTIFACT_IDENTITY_MISMATCH;
|
|
if (error.integrityCheck === "admitted-identity")
|
|
return ARTIFACT_ADMITTED_IDENTITY_STALE;
|
|
// A target that changed during the read is the model's `changed` kind.
|
|
return integrityCheckMeansChanged(error.integrityCheck)
|
|
? kindClassification("changed")
|
|
: ARTIFACT_OPERATION_CLASSIFICATIONS.integrity;
|
|
}
|
|
if (error instanceof BinaryTargetError)
|
|
return binaryTargetClassification(
|
|
error.constraint ?? "unconstrained",
|
|
error.systemCode !== undefined,
|
|
);
|
|
if (error instanceof EvidenceFileError)
|
|
return EVIDENCE_FILE_CLASSIFICATIONS[error.reason];
|
|
if (error instanceof ResourceSnapshotMismatchError)
|
|
return RESOURCE_SNAPSHOT_NOT_APPLICABLE;
|
|
if (error instanceof EvidenceReferenceError && error.reason === "missing")
|
|
return EVIDENCE_REFERENCE_MISSING;
|
|
if (error instanceof UnknownRegistryError)
|
|
return UNKNOWN_REGISTRY_CLASSIFICATIONS[error.reason];
|
|
if (error._tag === "ProcessCaptureError")
|
|
return error.userCategory === "cancelled"
|
|
? CANCELLED
|
|
: "retryable" in error && error.retryable === true
|
|
? { ...PROCESS_CAPTURE_FAILED, retry: "same_call" }
|
|
: PROCESS_CAPTURE_FAILED;
|
|
if (error instanceof AnalysisResourceConstraintError)
|
|
return {
|
|
...STATIC_ERROR_CLASSIFICATIONS.AnalysisResourceConstraintError,
|
|
retry: resourceConstraintRetry(error),
|
|
};
|
|
return staticClassification(error);
|
|
};
|
|
|
|
/**
|
|
* A resource refusal's producer declares whether the same request can be
|
|
* admitted later. Occupied capacity can; a fixed allowance cannot change;
|
|
* any other bound needs a changed request or limit first.
|
|
*/
|
|
const resourceConstraintRetry = (
|
|
error: AnalysisResourceConstraintError,
|
|
): AnalysisRetryClass =>
|
|
(error.retryable ?? error.resource === "capacity")
|
|
? "same_call"
|
|
: error.fixedAllowance === undefined
|
|
? "change_first"
|
|
: "never";
|
|
|
|
/** One row of the generated error catalogue. */
|
|
export interface AnalysisErrorCatalogueEntry extends AnalysisErrorClassification {
|
|
readonly tag: AnalysisErrorTag | ProviderErrorTag;
|
|
/** The fact that selects this row; empty when the tag alone does. */
|
|
readonly discriminant: string;
|
|
/**
|
|
* Whether the projection reports the case as retryable: its retry class is
|
|
* `same_call`. An error's own facts can still change the class: a resource
|
|
* constraint's recovery, a reader limit, a capture's retry flag, or a
|
|
* capability's declared availability.
|
|
*/
|
|
readonly retryableByDefault: boolean;
|
|
}
|
|
|
|
/**
|
|
* One catalogue row. A provider that presents its own errors lists them
|
|
* through this, so its rows read like the domain's.
|
|
*/
|
|
export const catalogueRow = (
|
|
tag: AnalysisErrorTag | ProviderErrorTag,
|
|
discriminant: string,
|
|
classification: AnalysisErrorClassification,
|
|
): AnalysisErrorCatalogueEntry => ({
|
|
tag,
|
|
discriminant,
|
|
...classification,
|
|
retryableByDefault: classification.retry === "same_call",
|
|
});
|
|
|
|
const reasonRows = (
|
|
tag: AnalysisErrorTag,
|
|
table: Readonly<Record<string, AnalysisErrorClassification>>,
|
|
): AnalysisErrorCatalogueEntry[] =>
|
|
Object.entries(table).map(([reason, classification]) =>
|
|
catalogueRow(tag, `reason=${reason}`, classification),
|
|
);
|
|
|
|
/**
|
|
* Every domain error case and its caller-facing code and category. A
|
|
* provider-owned error presents itself, and its provider lists its rows.
|
|
* Cleanup that did not complete reports `cleanup_incomplete` above any row.
|
|
*/
|
|
export const analysisErrorCatalogue =
|
|
(): readonly AnalysisErrorCatalogueEntry[] => [
|
|
...Object.entries(STATIC_ERROR_CLASSIFICATIONS).map(
|
|
([tag, classification]) =>
|
|
catalogueRow(tag as AnalysisErrorTag, "", classification),
|
|
),
|
|
catalogueRow(
|
|
"AnalysisCapabilityUnavailableError",
|
|
"retry=same_call",
|
|
availableLaterCapability("same_call"),
|
|
),
|
|
catalogueRow(
|
|
"AnalysisCapabilityUnavailableError",
|
|
"retry=change_first",
|
|
availableLaterCapability("change_first"),
|
|
),
|
|
...TARGET_FAILURE_KINDS.map((kind) =>
|
|
catalogueRow(
|
|
"AnalysisTargetFailureError",
|
|
`kind=${kind}`,
|
|
kindClassification(kind),
|
|
),
|
|
),
|
|
...reasonRows("ArtifactOperationError", ARTIFACT_OPERATION_CLASSIFICATIONS),
|
|
catalogueRow(
|
|
"ArtifactOperationError",
|
|
"reason=integrity; artifact identity reported",
|
|
ARTIFACT_IDENTITY_MISMATCH,
|
|
),
|
|
catalogueRow(
|
|
"ArtifactOperationError",
|
|
"reason=limit; release-fixed allowance",
|
|
{ ...ARTIFACT_OPERATION_CLASSIFICATIONS.limit, retry: "never" },
|
|
),
|
|
catalogueRow(
|
|
"ArtifactOperationError",
|
|
"reason=integrity; the session's admitted identity no longer matches",
|
|
ARTIFACT_ADMITTED_IDENTITY_STALE,
|
|
),
|
|
catalogueRow(
|
|
"ArtifactOperationError",
|
|
"reason=integrity; target changed during the read",
|
|
kindClassification("changed"),
|
|
),
|
|
...Object.keys(BINARY_TARGET_CLASSIFICATIONS).flatMap((key) => {
|
|
const constraint = key as BinaryTargetConstraintKey;
|
|
const allowed = binaryTargetClassification(constraint, false);
|
|
const denied = binaryTargetClassification(constraint, true);
|
|
return [
|
|
catalogueRow("BinaryTargetError", `constraint=${constraint}`, allowed),
|
|
...(denied.code === allowed.code
|
|
? []
|
|
: [
|
|
catalogueRow(
|
|
"BinaryTargetError",
|
|
`constraint=${constraint}; read permission denied`,
|
|
denied,
|
|
),
|
|
]),
|
|
];
|
|
}),
|
|
...reasonRows(
|
|
"BrowserObservationError",
|
|
BROWSER_OBSERVATION_CLASSIFICATIONS,
|
|
),
|
|
catalogueRow(
|
|
"BrowserObservationError",
|
|
"caused by cancellation",
|
|
CANCELLED,
|
|
),
|
|
...reasonRows("EvidenceFileError", EVIDENCE_FILE_CLASSIFICATIONS),
|
|
catalogueRow(
|
|
"EvidenceIntegrityError",
|
|
"analysis snapshot selected for a resource-only session",
|
|
RESOURCE_SNAPSHOT_NOT_APPLICABLE,
|
|
),
|
|
catalogueRow(
|
|
"EvidenceIntegrityError",
|
|
"referenced Evidence missing from this session",
|
|
EVIDENCE_REFERENCE_MISSING,
|
|
),
|
|
catalogueRow("ProcessCaptureError", "", PROCESS_CAPTURE_FAILED),
|
|
catalogueRow("ProcessCaptureError", "caused by cancellation", CANCELLED),
|
|
...reasonRows("ProviderSelectionError", PROVIDER_SELECTION_CLASSIFICATIONS),
|
|
...reasonRows("UnknownRegistryError", UNKNOWN_REGISTRY_CLASSIFICATIONS),
|
|
];
|