fix(browser): classify selected web trace file failures by cause (#1396)
trace_web_module_imports and trace_web_source_location reported a missing
or non-file manifest, source map or import map as artifact_operation_failed
("Artifact could not be read or written" / "unsafe or conflicting internal
path"). These are caller selections: report ENOENT/ENOTDIR and non-regular
files as invalid input on the selected field, and EACCES/EPERM as a host
access denial. A missing manifest-derived source file stays an artifact fault.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
498cec042a
commit
2b6e9ec03f
@@ -25,6 +25,7 @@ export class LocalWebScriptArtifacts implements WebScriptArtifactPort {
|
||||
async load(input: SelectedWebScriptInput, options?: ExecutionOptions) {
|
||||
let field: readonly (string | number)[] = ["manifest_path"];
|
||||
let targetPath = input.manifest_path;
|
||||
let callerSelected = true;
|
||||
try {
|
||||
const manifestBytes = await readWebArtifactJson(
|
||||
input.manifest_path,
|
||||
@@ -58,6 +59,7 @@ export class LocalWebScriptArtifacts implements WebScriptArtifactPort {
|
||||
const root = resolve(dirname(input.manifest_path));
|
||||
const sourcePath = join(root, "files", portable);
|
||||
targetPath = sourcePath;
|
||||
callerSelected = false;
|
||||
await assertContained(root, sourcePath);
|
||||
const sourceBytes = await readStableArtifact(
|
||||
sourcePath,
|
||||
@@ -99,7 +101,7 @@ export class LocalWebScriptArtifacts implements WebScriptArtifactPort {
|
||||
return err(
|
||||
webArtifactReadError(
|
||||
cause,
|
||||
{ operation: this.operation, field, targetPath },
|
||||
{ operation: this.operation, field, targetPath, callerSelected },
|
||||
options?.signal,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -3,6 +3,7 @@ import { ArtifactReaderFailure } from "../../artifacts/ArtifactReader.js";
|
||||
import { readStableArtifact } from "../../artifacts/readStableArtifact.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import {
|
||||
AnalysisAccessDeniedError,
|
||||
AnalysisCancelledError,
|
||||
AnalysisInputError,
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
@@ -15,6 +16,8 @@ export interface WebArtifactReadContext {
|
||||
readonly operation: "trace_web_module_imports" | "trace_web_source_location";
|
||||
readonly field: readonly (string | number)[];
|
||||
readonly targetPath: string;
|
||||
/** Whether the caller named this file, rather than a manifest deriving it. */
|
||||
readonly callerSelected: boolean;
|
||||
}
|
||||
|
||||
/** A malformed producer document, distinct from host I/O failures. */
|
||||
@@ -54,6 +57,10 @@ export const webArtifactReadError = (
|
||||
): AnalysisError => {
|
||||
if (signal?.aborted === true)
|
||||
return new AnalysisCancelledError(context.operation);
|
||||
const selection = context.callerSelected
|
||||
? selectedFileError(cause, context)
|
||||
: undefined;
|
||||
if (selection !== undefined) return selection;
|
||||
if (cause instanceof ArtifactReaderFailure)
|
||||
return new ArtifactOperationError(
|
||||
context.operation,
|
||||
@@ -91,3 +98,33 @@ export const webArtifactReadError = (
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Report a missing, non-regular or unreadable caller-selected file as the
|
||||
* caller's selection or a host permission denial, not an artifact fault.
|
||||
*/
|
||||
const selectedFileError = (
|
||||
cause: unknown,
|
||||
context: WebArtifactReadContext,
|
||||
): AnalysisError | undefined => {
|
||||
const selected = (message: string) =>
|
||||
new AnalysisInputError(context.operation, { cause }, [
|
||||
{ path: context.field, reason: "invalid_value", message },
|
||||
]);
|
||||
if (cause instanceof ArtifactReaderFailure)
|
||||
return cause.reason === "path" ? selected(cause.message) : undefined;
|
||||
const code =
|
||||
cause instanceof Error && "code" in cause ? String(cause.code) : "";
|
||||
if (code === "EACCES" || code === "EPERM")
|
||||
return new AnalysisAccessDeniedError(
|
||||
context.operation,
|
||||
context.targetPath,
|
||||
code,
|
||||
{ cause },
|
||||
);
|
||||
if (code === "ENOENT" || code === "ENOTDIR")
|
||||
return selected(
|
||||
`Selected file could not be read (${code}): ${context.targetPath}`,
|
||||
);
|
||||
return undefined;
|
||||
};
|
||||
|
||||
@@ -48,6 +48,7 @@ export class LocalWebSourceLocationArtifacts implements WebSourceLocationArtifac
|
||||
operation: "trace_web_source_location",
|
||||
field: ["source_map", "path"],
|
||||
targetPath: input.source_map.path,
|
||||
callerSelected: true,
|
||||
},
|
||||
options?.signal,
|
||||
),
|
||||
|
||||
@@ -52,6 +52,7 @@ export class LocalWebModuleArtifacts implements WebModuleArtifactPort {
|
||||
operation: "trace_web_module_imports",
|
||||
field: ["import_map", "path"],
|
||||
targetPath: selected.path,
|
||||
callerSelected: true,
|
||||
},
|
||||
options?.signal,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user