Skip to content

Commit

Permalink
chore: Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
smessie committed Dec 23, 2024
1 parent 0209720 commit b004d37
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
30 changes: 19 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/exitHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ export function Cleanup(callback: () => void | Promise<void>) {

// Make sure we only call the callback once.
let callbackCalled = false;
const fn = async function (event: string, code?: number) {
const fn = async function (event: string, code?: number, message?: Error) {
if (!callbackCalled) {
callbackCalled = true;
logger.debug(
`[Cleanup] Callback called on '${event}' with code '${code}'.`,
);
if (message) {
logger.error(
`[Cleanup] Uncaught Exception: ${message.name} - ${message.message}`,
);
logger.debug(message.stack);
}
await callback();
} else {
logger.debug(
Expand All @@ -41,6 +47,6 @@ export function Cleanup(callback: () => void | Promise<void>) {
//catch uncaught exceptions, trace, then exit normally
process.on(
"uncaughtException",
async () => await fn("uncaughtException", 99),
async (error) => await fn("uncaughtException", 99, error),
);
}

0 comments on commit b004d37

Please sign in to comment.