Skip to content
This repository was archived by the owner on Jul 2, 2025. It is now read-only.

Commit 48d3b2d

Browse files
committed
properly error out when prettier fails
1 parent 4a43acd commit 48d3b2d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/cli.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,14 @@ export async function runCli(
110110

111111
// if we ever need to add more language special cases here (beyond yaml files), this should be generalized into an array
112112
const formatCommand = `prettier ${defaultFiles} --config "${configFiles.prettierDefault.copyToPath}" ${prettierFlags} && prettier ${yamlFiles} --config "${configFiles.prettierYaml.copyToPath}" ${prettierFlags}`;
113-
await runShellCommand(interpolationSafeWindowsPath(formatCommand), {
113+
const prettierResult = await runShellCommand(interpolationSafeWindowsPath(formatCommand), {
114114
cwd,
115115
hookUpToConsole: shouldLog,
116116
});
117+
if (prettierResult.exitCode !== 0) {
118+
// no need to include anything in the error, hookUpToConsole above will handle all error logging.
119+
throw new Error();
120+
}
117121
} else {
118122
const errors: Error[] = [];
119123
await awaitedForEach(getObjectTypedKeys(configFiles), async (configFileName) => {
@@ -145,7 +149,6 @@ if (require.main === module) {
145149
const {command, args} = getCommands();
146150

147151
runCli(process.cwd(), command, args, true).catch((error) => {
148-
console.error(error);
149152
process.exit(1);
150153
});
151154
}

0 commit comments

Comments
 (0)