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

test-node-top-level-failure-handles #37

Open
colinwilliams91 opened this issue Apr 8, 2024 · 0 comments
Open

test-node-top-level-failure-handles #37

colinwilliams91 opened this issue Apr 8, 2024 · 0 comments

Comments

@colinwilliams91
Copy link
Contributor

colinwilliams91 commented Apr 8, 2024

Describe the Problem

In production, the app should have a few different avenues to gracefully fail (log, resume/restart)
top-level path: src\index.ts

Describe the Proposed Solution

In the "references" section there are 3 different process.on event listeners/handlers. Consider them from top to bottom ordered like this: 1, 2, 3

  1. uncaughtExceptionMonitor
  • create custom monitor class here that will handle application recover or restart from unhandled critical failure...
  1. unhandledRejection
  • implement application logging (just the invocations if Monitor class is robust enough), throwing an error, or other logic
  1. uncaughtException
  • test where fs.writeSync is outputting to, set up debugger/developer log directory...

References

/////////////////////////////////////////////////////////
///// #region top-level node critical-failure catch /////
process.on('uncaughtExceptionMonitor', (err, origin) => {
  console.error(`Critical failure, propagated to top-level from ${origin}, error: `, err);
  /* TODO: create custom monitor class here that will handle application recover or restart from unhandled critical failure... */
});

process.on('unhandledRejection', (reason, promise) => {
  console.log('Unhandled Rejection at:', promise, 'reason:', reason);
  /* TODO: application logging, throwing an error, or other logic here (bubbled up unhandled promises) */
});

process.on('uncaughtException', (err, origin) => {
  console.error("Critical Error -- app is about to explode... \n performing synchronous cleanup.. \n writing crash state to log file..");
  fs.writeSync(
    process.stderr.fd,
    `Caught exception: ${err}\n` +
    `Exception origin: ${origin}\n`,
  );
  console.error("goodbye.");
});
/////////////////////////////////////////////////////////
// #endregion ///////////////////////////////////////////
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

1 participant