Skip to content

Commit 6f5953c

Browse files
committed
refactor(cli/parsers/config-file-parser): better error messages
1 parent e493e36 commit 6f5953c

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

packages/cli/src/parsers/config-file-parser.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@ export function parseConfigFile(filename: string, previous: unknown, validator:
2323
const data = readFileSync(open, "utf-8");
2424
if (!validator(JSON.parse(data))) {
2525
throw new InvalidArgumentError(
26-
`Config file contains invalid an JSON: ${(validator.errors ?? [])
27-
.map((o: ErrorObject) => o.message)
26+
`\n\nConfig file contains an invalid JSON structure:\n ${(validator.errors ?? [])
27+
.map((o: ErrorObject) => `\tError ${o.instancePath || "root"}: ${o.message}`)
2828
.join("\n")}`
2929
);
3030
}
3131
return filename;
3232
} catch (err) {
33-
throw new InvalidArgumentError(`Error reading config file: ${err}`);
33+
if (err instanceof InvalidArgumentError) {
34+
throw err;
35+
}
36+
throw new InvalidArgumentError(`\nError reading config file: ${err}`);
3437
}
3538
}

0 commit comments

Comments
 (0)