perish
v1.0.3
Published
tiny module to log and exit on uncaughtException and unhandledRejection events
Downloads
502
Maintainers
Readme
perish
tiny module to log and exit on uncaughtException and unhandledRejection events
install
npm install --save(-dev) perish
usage
require('perish')
that's all. in any nodejs file.
what
listen for uncaughtException
& unhandledRejection
in node processes. when those events occur, log the message and the stack, then exit with exit code 1
.
why
because apps should die hard if their errors aren't handled. some apps require graceful exit onerror. sometimes this is feasible, sometimes this is not. this package is simple and just exits.
example
// unhandled.js
Promise.reject(new Error('bananas'))
run node unhandled.js
and ... nothing.
// handled.js
require('perish')
Promise.reject(new Error('bananas'))
run node handled.js
and:
Error: bananas
at Object.<anonymous> (/some/path/handled.js:2:16)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Function.Module.runMain (module.js:575:10)
at startup (node.js:160:18)
at node.js:456:3
nothin' too fancy!
api
const perish = require('perish')
perish.printStacktrace // default true. set to false to console.error error message only
perish.fail // @private. this is the error handler