Added handler for unhandled rejections

refs https://github.com/TryGhost/Toolbox/issues/163

- as of Node 15, unhandled rejections will exit the process so if
  Ghost is running on Node 15+ and encounters one, it will kill Ghost
- if Sentry is enabled, it will add a handler for the event that will
  send it to Sentry but the logging is sent to stdout/stderr, which means
  we lose it in Ghost logs
- this commit adds a process handler for the `unhandledRejection` event
  which will log the reason to Ghost logs and prevent Ghost from
  exiting
This commit is contained in:
Daniel Lockyer 2022-02-18 10:28:28 +01:00
parent 32884fa412
commit 3ad871b21e
No known key found for this signature in database
GPG Key ID: D21186F0B47295AD

View File

@ -358,6 +358,13 @@ async function bootGhost({backend = true, frontend = true, server = true} = {})
debug('End: Load logging');
// At this point logging is required, so we can handle errors better
// Add a process handler to capture and log unhandled rejections
debug('Begin: Add unhandled rejection handler');
process.on('unhandledRejection', (error) => {
logging.error('Unhandled rejection:', error);
});
debug('End: Add unhandled rejection handler');
} catch (error) {
console.error(error); // eslint-disable-line no-console
process.exit(1);