Skip to content

feat: Log unhandledRejection & uncaughtException #1733

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

benscobie
Copy link
Collaborator

Description

This PR adds logging to unhandledRejection and uncaughtException events. We use the framework logger so that the exception ends up in the app log file as well as the console. Usually it would end up in stderr, meaning the user would need to dig into their Docker logs.

Typically unhandledRejection's would cause a process exit, but here I am allowing the program to continue. These are likely to be from our usage of throw away Promises that do not have a catch attached. We should either be awaiting these or attaching a catch.

uncaughtException events will cause the process to exit, as it would usually.

I've also updated the exit code when data directory validation fails, as 0 signals a success.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my code.
  • I have linted and formatted my code.
  • My changes generate no new warnings.
  • New and existing unit tests pass locally with my changes.

How to test

Please describe the steps to test your changes, including any setup required.

Create a scenario where an unhandled reject would occur. I used this in rules.controller.ts executeRules and then "Run rules":

setTimeout(() => {
      throw new Error('Test error');
    }, 500);

@benscobie benscobie requested review from ydkmlt84 and jorenn92 April 19, 2025 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant