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:
Kaoru0822
2026-10-09 09:30:15 +00:00
co-authored by Claude Opus 5.5
parent aa5750c263
commit 6020df53d9
2 changed files with 67 additions and 3 deletions
+17 -1
View File
@@ -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 ?? ""}`,
};
};