Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error handling #82

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
);
}
Loading