Merge pull request #1259 from morluto/fix/cli-json-input-read-cause

fix(cli): list the read failure cause for an unreadable JSON input file
This commit is contained in:
Kaoru0822
2026-10-09 02:47:42 -07:00
committed by GitHub
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 ?? ""}`,
};
};