Package Exports
- log-process-errors
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (log-process-errors) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Log any process errors:
uncaughtException: an exception was thrown and not caughtunhandledRejection: a promise was rejected and not handledrejectionHandled: a promise was rejected and handled too latemultipleResolves: a promise was resolved/rejected twicewarning: a warning was produced usingprocess.emitWarning()
Usage
const logProcessErrors = require('log-process-errors')
const undoSetup = lopProcessErrors.setup()When any process errors occur, it will be logged using console.error().
The message will include detailed information about the error.
For warning, console.warn() will be used instead.
You can undo everything by firing the function returned by
onProcessError.setup() (called undoSetup in the example above).
Example output
TO BE DONE
Custom handling
You can override the default behavior by passing a custom function to the
handle option.
onProcessError.setup({
handle({ eventName, promiseState, promiseValue, error, message }) {},
})This can be useful if you want to use your own logger instead of the console.
The function's argument is an object with the following properties:
eventName{string}: can beuncaughtException,unhandledRejection,rejectionHandled,multipleResolvesorwarningerror{any}is either:- value thrown by
uncaughtException. Usually anErrorinstance, but not always. Errorinstance emitted bywarning.error.name,error.codeanderror.detailmight be defined.
- value thrown by
promiseState{string}: whether promise wasresolvedorrejected. ForunhandledRejection,rejectionHandledandmultipleResolves.promiseValue{any}: value resolved/rejected by the promise. ForunhandledRejection,rejectionHandledandmultipleResolves.message{string}: detailed message summing up all of the above.
Exiting on uncaught exceptions
By default, uncaughtException will fire process.exit(1). This is the recommended behavior according to the
Node.js documentation.
You can disable this by setting the exitOnExceptions option to false:
onProcessError.setup({ exitOnExceptions: false })