Skip to content

Commit

Permalink
Add output and error handling to hook-runner
Browse files Browse the repository at this point in the history
  • Loading branch information
marclefrancois committed Mar 1, 2024
1 parent d8e3a70 commit 0ae10dd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 7 additions & 0 deletions cli/src/services/formatters/hook-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@ export default class HookRunnerFomatter {
});
console.log('');
}
error(command: string, errors: string[]) {
console.log(chalk.red('⚠ '), chalk.bold(chalk.red(`${command}:`)));
errors.forEach((error) => {
console.log(' ', chalk.red(error));
});
console.log('');
}
}
15 changes: 12 additions & 3 deletions cli/src/services/hook-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,18 @@ export default class HookRunner {
const hooks = this.hooks[name];

if (hooks) {
new Formatter().log(name, hooks);

hooks.forEach(execSync);
const formatter = new Formatter()
formatter.log(name, hooks);

hooks.forEach((hook) => {
try {
const output: string = execSync(hook, { stdio: 'pipe' }).toString();
formatter.log(hook, [output])
} catch (error: any) {
formatter.error(hook, [error.stderr.toString()]);
throw new Error(`Hook execution failed for '${hook}': ${error.stderr.toString()}`);
}
});
}

return this.document.refreshPaths();
Expand Down

0 comments on commit 0ae10dd

Please sign in to comment.