mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-03 04:07:03 +00:00
fix(cli): say stdin was empty when a JSON flag reads - and nothing is piped (#6852)
This commit is contained in:
@@ -35,6 +35,12 @@ describe("readJsonFlag", () => {
|
||||
expect(() => readJsonFlag("--grading", "C:\\clips\\grade.json", io)).toThrow(/no such file$/);
|
||||
});
|
||||
|
||||
it("says stdin was empty instead of a JSON parse error", () => {
|
||||
expect(() => readJsonFlag("--grading", "-", { ...io, readStdin: () => "\n" })).toThrow(
|
||||
/Could not read --grading: stdin: nothing was piped in/,
|
||||
);
|
||||
});
|
||||
|
||||
it("names the flag and path when the file cannot be read", () => {
|
||||
expect(() => readJsonFlag("--grading", "missing.json", io)).toThrow(
|
||||
/Could not read --grading: missing\.json: ENOENT/,
|
||||
|
||||
@@ -51,7 +51,10 @@ export function readJsonFlagText(value: string, partialIo: Partial<JsonFlagIO> =
|
||||
if (trimmed.startsWith("{") || trimmed.startsWith("[") || isJsonScalar(trimmed)) return value;
|
||||
const source = trimmed === "-" ? "stdin" : value;
|
||||
try {
|
||||
return trimmed === "-" ? io.readStdin() : io.readFile(value);
|
||||
if (trimmed !== "-") return io.readFile(value);
|
||||
const piped = io.readStdin();
|
||||
if (!piped.trim()) throw new Error("nothing was piped in");
|
||||
return piped;
|
||||
} catch (error: unknown) {
|
||||
throw new JsonFlagReadError(source, errorText(error));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user