Skip to content

Commit

Permalink
log unhandled errors
Browse files Browse the repository at this point in the history
  • Loading branch information
williamhorning committed Aug 24, 2024
1 parent 0d86351 commit 1fda5ad
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/lightning/src/cli/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,28 @@ if (cmd === 'version') {

Deno.env.set('LIGHTNING_ERROR_HOOK', cfg.errorURL || '');

addEventListener('unhandledrejection', async (e) => {
if (e.reason instanceof Error) {
await log_error(e.reason);
} else {
await log_error(new Error('global rejection'), {
extra: e.reason,
});
}

Deno.exit(1);
});

addEventListener('error', async (e) => {
if (e.error instanceof Error) {
await log_error(e.error);
} else {
await log_error(new Error('global error'), { extra: e.error });
}

Deno.exit(1);
});

try {
new lightning(
cfg,
Expand Down

0 comments on commit 1fda5ad

Please sign in to comment.