fix(cli): list the read failure cause for an unreadable JSON input file
A CLI workflow given a JSON input file that cannot be read (missing, a directory, or permission denied) returned invalid_request with input_reason "read-failed" but no details. The remediation "Correct the listed arguments and retry." therefore listed nothing, and the system error that separates a typo from a permission denial was dropped. Add an invalid_value issue naming the system error code and the path. The envelope, code and input_reason are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
aa5750c263
commit
6020df53d9
+17
-1
@@ -128,10 +128,26 @@ const jsonFileError = (
|
||||
cause === undefined ? undefined : { cause },
|
||||
reason === "invalid-json"
|
||||
? [{ path: [], reason: "invalid_format", expected: "JSON" }]
|
||||
: [],
|
||||
: [readFailureIssue(path, cause)],
|
||||
),
|
||||
),
|
||||
...(path === undefined ? {} : { input_path: path }),
|
||||
input_reason: reason,
|
||||
},
|
||||
});
|
||||
|
||||
/** Name the system error so the caller can tell a typo from a permission denial. */
|
||||
const readFailureIssue = (path: string | undefined, cause: unknown) => {
|
||||
const code =
|
||||
typeof cause === "object" &&
|
||||
cause !== null &&
|
||||
"code" in cause &&
|
||||
typeof cause.code === "string"
|
||||
? ` (${cause.code})`
|
||||
: "";
|
||||
return {
|
||||
path: [],
|
||||
reason: "invalid_value" as const,
|
||||
message: `The JSON input file could not be read${code}: ${path ?? ""}`,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user