Skip to content

Commit 788d454

Browse files
committed
feat: even better config error logging
1 parent 184e4ce commit 788d454

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import chalk from "chalk";
1010
import { Command } from "commander";
1111
import dotenv from "dotenv";
1212
import signale from "signale";
13+
import { fromError } from "zod-validation-error";
1314

1415
import { description, version } from "./package.json";
1516
import { machBuild, machWatch } from "./src/mach";
@@ -56,11 +57,12 @@ const commandWithOptions = (name: string) =>
5657
await import(config.replace(/\\/g, "/"))
5758
.then((module) => {
5859
// Check config integrity
59-
try {
60-
actionCommand.setOptionValue("config", MachConfigSchema.parse(module.default));
61-
} catch (error) {
60+
const result = MachConfigSchema.safeParse(module.default);
61+
if (result.success) {
62+
actionCommand.setOptionValue("config", result.data);
63+
} else {
6264
logger.error("Invalid config file", chalk.redBright(config));
63-
logger.error(error);
65+
logger.error(chalk.white(fromError(result.error)));
6466
process.exit(1);
6567
}
6668

package-lock.json

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"filesize": "^10.1.6",
3131
"signale": "^1.4.0",
3232
"template-file": "^6.0.1",
33-
"zod": "^3.24.1"
33+
"zod": "^3.24.1",
34+
"zod-validation-error": "3.4.0"
3435
},
3536
"devDependencies": {
3637
"@biomejs/biome": "1.9.4",

0 commit comments

Comments
 (0)