fix(cli): classify JSON input permission denials
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
} from "./application/RegularFileRead.js";
|
||||
import { parseUtf8Json } from "./application/Utf8JsonInput.js";
|
||||
import {
|
||||
AnalysisAccessDeniedError,
|
||||
AnalysisInputError,
|
||||
AnalysisResourceConstraintError,
|
||||
} from "./domain/analysisErrorCore.js";
|
||||
@@ -49,6 +50,9 @@ export const parseCliJsonInput = async (
|
||||
input_reason: "too-large",
|
||||
},
|
||||
};
|
||||
const systemCode = accessDeniedSystemCode(cause);
|
||||
if (systemCode !== undefined)
|
||||
return jsonAccessDeniedError(value, operation, systemCode, cause);
|
||||
if (
|
||||
["{", "["].includes(value.trimStart()[0] ?? "") &&
|
||||
cannotBeAnExistingFile(cause) &&
|
||||
@@ -59,6 +63,15 @@ export const parseCliJsonInput = async (
|
||||
}
|
||||
};
|
||||
|
||||
const accessDeniedSystemCode = (
|
||||
cause: unknown,
|
||||
): "EACCES" | "EPERM" | undefined => {
|
||||
if (!(cause instanceof Error) || !("code" in cause)) return undefined;
|
||||
return cause.code === "EACCES" || cause.code === "EPERM"
|
||||
? cause.code
|
||||
: undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* Resolve named string fields of CLI-supplied JSON against the operator
|
||||
* working directory. Each entry is a key path from the document root; only
|
||||
@@ -148,6 +161,23 @@ const jsonFileError = (
|
||||
},
|
||||
});
|
||||
|
||||
const jsonAccessDeniedError = (
|
||||
path: string,
|
||||
operation: string,
|
||||
systemCode: "EACCES" | "EPERM",
|
||||
cause: unknown,
|
||||
) => ({
|
||||
ok: false as const,
|
||||
error: {
|
||||
error: "Application workflow failed",
|
||||
...projectAnalysisError(
|
||||
new AnalysisAccessDeniedError(operation, path, systemCode, { cause }),
|
||||
),
|
||||
input_path: path,
|
||||
input_reason: "read-failed" as const,
|
||||
},
|
||||
});
|
||||
|
||||
/** Preserve file-selection and system failures alongside the requested path. */
|
||||
const readFailureIssue = (path: string | undefined, cause: unknown) => {
|
||||
const code =
|
||||
|
||||
Reference in New Issue
Block a user