inspect_wasm_artifact's configuration-phase error handler assumed every non-OwnedCommandFailure thrown before the artifact phase was about WABT tool/directory resolution, and unconditionally appended "Supply WABT 1.0.42 via absolute REA_WABT_BIN_DIRECTORY; REA does not install tools." to the reason. WabtArtifactProvider.inspect() also allocates its PrivateRuntimeRoot during the configuration phase, so a PrivateRuntimeRootUnavailableError (the Windows native-authority capability, unrelated to WABT) got the same false remediation glued onto its own already-correct message, misdirecting anyone troubleshooting a correctly-configured WABT install toward re-checking WABT instead of the real blocker. Classify PrivateRuntimeRootUnavailableError before the generic configuration-phase branch, matching the existing convention already used in JavaScriptAnalysisWorker.ts and SourceMapCommand.ts: surface it as its own AnalysisCapabilityUnavailableError with no userMessage override, letting its own message stand. Verified against a real WABT 1.0.42 Windows release (hash-checked against GitHub release metadata) and a real compiled .wasm module: before the fix, `reason` read "REA Windows native controls are unavailable: ENOENT: ... Supply WABT 1.0.42 ..." even with a fully correct REA_WABT_BIN_DIRECTORY; after, `reason` reports only the real cause.
120 lines
4.1 KiB
TypeScript
120 lines
4.1 KiB
TypeScript
import { ArtifactReaderFailure } from "../artifacts/ArtifactReader.js";
|
|
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
|
import {
|
|
AnalysisCancelledError,
|
|
AnalysisArtifactChangedError,
|
|
AnalysisAccessDeniedError,
|
|
AnalysisInputError,
|
|
AnalysisOutputError,
|
|
AnalysisTimeoutError,
|
|
AnalysisCapabilityUnavailableError,
|
|
} from "../domain/analysisErrorCore.js";
|
|
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
|
|
import { OwnedCommandFailure } from "../process/OwnedCommand.js";
|
|
import { PrivateRuntimeRootUnavailableError } from "../process/PrivateRuntimeRoot.js";
|
|
import { WABT_LIMITS, WABT_PROVIDER_IDENTITY } from "./WabtRelease.js";
|
|
/** Preserve lifecycle failures and diagnostic bytes instead of returning partial success. */
|
|
export const wabtFailure = (
|
|
cause: unknown,
|
|
phase: "configuration" | "artifact" | "producer",
|
|
path: string,
|
|
): AnalysisError => {
|
|
if (cause instanceof AnalysisError) return cause;
|
|
const reason = cause instanceof Error ? cause.message : String(cause);
|
|
if (
|
|
(cause instanceof ArtifactReaderFailure && cause.reason === "cancelled") ||
|
|
(cause instanceof Error && cause.name === "AbortError")
|
|
)
|
|
return new AnalysisCancelledError("inspect_wasm_artifact", { cause });
|
|
if (cause instanceof OwnedCommandFailure) {
|
|
const capturedOutput =
|
|
cause.snapshot === null
|
|
? undefined
|
|
: {
|
|
stdout: cause.snapshot.stdout.text,
|
|
stderr: cause.snapshot.stderr.text,
|
|
truncated: cause.snapshot.diagnosticTruncated ?? false,
|
|
};
|
|
const options =
|
|
capturedOutput === undefined ? { cause } : { cause, capturedOutput };
|
|
if (cause.cleanupFailure !== null)
|
|
return new ProviderCleanupError(
|
|
WABT_PROVIDER_IDENTITY.id,
|
|
cause.resources,
|
|
{
|
|
reason: cause.cleanupFailure,
|
|
previous_error: reason,
|
|
...(capturedOutput === undefined
|
|
? {}
|
|
: { captured_output: capturedOutput }),
|
|
},
|
|
{ operation: "inspect_wasm_artifact", cause },
|
|
);
|
|
if (cause.reason === "cancelled")
|
|
return new AnalysisCancelledError("inspect_wasm_artifact", options);
|
|
if (cause.reason === "timeout")
|
|
return new AnalysisTimeoutError(
|
|
"inspect_wasm_artifact",
|
|
WABT_LIMITS.timeoutMs,
|
|
options,
|
|
);
|
|
if (phase === "configuration" && cause.reason === "process")
|
|
return new AnalysisCapabilityUnavailableError(
|
|
WABT_PROVIDER_IDENTITY.id,
|
|
"inspect_wasm_artifact",
|
|
reason,
|
|
{
|
|
...options,
|
|
userMessage:
|
|
"Configured WABT could not start. Check executable/interpreter access and WABT 1.0.42 profile; inspect retained diagnostics.",
|
|
},
|
|
);
|
|
return new AnalysisOutputError("inspect_wasm_artifact", reason, options);
|
|
}
|
|
if (cause instanceof PrivateRuntimeRootUnavailableError)
|
|
return new AnalysisCapabilityUnavailableError(
|
|
WABT_PROVIDER_IDENTITY.id,
|
|
"inspect_wasm_artifact",
|
|
reason,
|
|
{ cause },
|
|
);
|
|
if (phase === "configuration")
|
|
return new AnalysisCapabilityUnavailableError(
|
|
WABT_PROVIDER_IDENTITY.id,
|
|
"inspect_wasm_artifact",
|
|
reason,
|
|
{
|
|
cause,
|
|
userMessage: `${reason} Supply WABT 1.0.42 via absolute REA_WABT_BIN_DIRECTORY; REA does not install tools.`,
|
|
},
|
|
);
|
|
if (
|
|
phase === "artifact" &&
|
|
cause instanceof ArtifactReaderFailure &&
|
|
cause.reason === "integrity"
|
|
)
|
|
return new AnalysisArtifactChangedError(
|
|
"inspect_wasm_artifact",
|
|
path,
|
|
reason,
|
|
{ cause },
|
|
);
|
|
if (
|
|
phase === "artifact" &&
|
|
cause instanceof Error &&
|
|
"code" in cause &&
|
|
(cause.code === "EACCES" || cause.code === "EPERM")
|
|
)
|
|
return new AnalysisAccessDeniedError(
|
|
"inspect_wasm_artifact",
|
|
path,
|
|
cause.code,
|
|
{ cause },
|
|
);
|
|
if (phase === "artifact")
|
|
return new AnalysisInputError("inspect_wasm_artifact", { cause }, [
|
|
{ path: ["path"], reason: "invalid_value", message: reason },
|
|
]);
|
|
return new AnalysisOutputError("inspect_wasm_artifact", reason, { cause });
|
|
};
|