Skip to content

Commit

Permalink
feat: log the stack trace in case of error for task commands
Browse files Browse the repository at this point in the history
  • Loading branch information
adbayb committed Oct 19, 2024
1 parent aec9fa0 commit d265c04
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/rich-rings-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"termost": minor
---

Log the stack trace in case of task error(s).
14 changes: 13 additions & 1 deletion termost/src/api/task/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const createTask: CreateInstruction<

const receiver = label
? new Listr([], {
collectErrors: "minimal",
exitOnError: true,
rendererOptions: {
collapseErrors: false,
formatOutput: "wrap",
Expand All @@ -43,7 +45,17 @@ export const createTask: CreateInstruction<
task: async () => (value = await handler(context, argv)),
});

await receiver.run();
try {
await receiver.run();
} catch (error) {
if (error instanceof Error && error.stack) {
console.error("\x1b[31m");
console.error(error.stack);
console.error("\x1b[0m");
}

throw error;
}
}

return { key, value };
Expand Down

0 comments on commit d265c04

Please sign in to comment.