Skip to content

Commit

Permalink
fix: exiting with code 1 on error to fail CI
Browse files Browse the repository at this point in the history
  • Loading branch information
tvillaren committed Feb 19, 2024
1 parent afdb4dd commit 95ecc61
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,29 +140,32 @@ class TsToZod extends Command {
this.error(`INPUT and OUTPUT arguments are not compatible with --all`);
}
try {
let hasError = false;
await Promise.all(
fileConfig.map(async (config) => {
this.log(`Generating "${config.name}"`);
const result = await this.generate(args, config, flags, ioMappings);
if (result.success) {
this.log(` 🎉 Zod schemas generated!`);
} else {
hasError = true;
this.error(result.error, { exit: false });
}
this.log(); // empty line between configs
})
);
if (hasError) this.exit(1);
} catch (e) {
const error =
typeof e === "string" || e instanceof Error ? e : JSON.stringify(e);
this.error(error);
this.error(error, { exit: 1 });
}
} else {
const result = await this.generate(args, fileConfig, flags, ioMappings);
if (result.success) {
this.log(`🎉 Zod schemas generated!`);
} else {
this.error(result.error);
this.error(result.error, { exit: 1 });
}
}

Expand Down

0 comments on commit 95ecc61

Please sign in to comment.