hard-rejection
Advanced tools
Comparing version 1.0.0 to 2.0.0
16
index.js
@@ -6,3 +6,3 @@ 'use strict'; | ||
module.exports = log => { | ||
const hardRejection = (log = console.error) => { | ||
if (installed) { | ||
@@ -13,12 +13,14 @@ return; | ||
installed = true; | ||
log = log || console.error; | ||
process.on('unhandledRejection', err => { | ||
if (!(err instanceof Error)) { | ||
err = new Error(`Promise rejected with value: ${util.inspect(err)}`); | ||
process.on('unhandledRejection', error => { | ||
if (!(error instanceof Error)) { | ||
error = new Error(`Promise rejected with value: ${util.inspect(error)}`); | ||
} | ||
log(err.stack); | ||
process.exit(1); // eslint-disable-line unicorn/no-process-exit | ||
log(error.stack); | ||
process.exit(1); | ||
}); | ||
}; | ||
module.exports = hardRejection; | ||
module.exports.default = hardRejection; |
{ | ||
"name": "hard-rejection", | ||
"version": "1.0.0", | ||
"description": "Make unhandled promise rejections fail hard right away instead of the default silent fail", | ||
"license": "MIT", | ||
"repository": "sindresorhus/hard-rejection", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"register.js" | ||
], | ||
"keywords": [ | ||
"promise", | ||
"promises", | ||
"unhandled", | ||
"uncaught", | ||
"rejection", | ||
"hard", | ||
"fail", | ||
"catch", | ||
"throw", | ||
"handler", | ||
"exit", | ||
"debug", | ||
"debugging", | ||
"verbose", | ||
"immediate", | ||
"immediately" | ||
], | ||
"devDependencies": { | ||
"ava": "*", | ||
"execa": "^0.6.0", | ||
"xo": "*" | ||
} | ||
"name": "hard-rejection", | ||
"version": "2.0.0", | ||
"description": "Make unhandled promise rejections fail hard right away instead of the default silent fail", | ||
"license": "MIT", | ||
"repository": "sindresorhus/hard-rejection", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava && tsd-check" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"index.d.ts", | ||
"register.js" | ||
], | ||
"keywords": [ | ||
"promise", | ||
"promises", | ||
"unhandled", | ||
"uncaught", | ||
"rejection", | ||
"hard", | ||
"fail", | ||
"catch", | ||
"throw", | ||
"handler", | ||
"exit", | ||
"debug", | ||
"debugging", | ||
"verbose", | ||
"immediate", | ||
"immediately" | ||
], | ||
"devDependencies": { | ||
"ava": "^1.3.1", | ||
"execa": "^1.0.0", | ||
"tsd-check": "^0.5.0", | ||
"xo": "^0.24.0" | ||
} | ||
} |
@@ -17,3 +17,3 @@ # hard-rejection [![Build Status](https://travis-ci.org/sindresorhus/hard-rejection.svg?branch=master)](https://travis-ci.org/sindresorhus/hard-rejection) | ||
``` | ||
$ npm install --save hard-rejection | ||
$ npm install hard-rejection | ||
``` | ||
@@ -26,8 +26,8 @@ | ||
const hardRejection = require('hard-rejection'); | ||
const promiseFn = require('some-promise-fn'); | ||
const promiseFunction = require('some-promise-fn'); | ||
// install the handler | ||
// Install the handler | ||
hardRejection(); | ||
promiseFn(); | ||
promiseFunction(); | ||
``` | ||
@@ -38,10 +38,10 @@ | ||
```js | ||
const promiseFn = require('some-promise-fn'); | ||
const promiseFunction = require('some-promise-fn'); | ||
function error(err) { | ||
console.error(err.stack); | ||
function error(error) { | ||
console.error(error.stack); | ||
process.exit(1); | ||
} | ||
promiseFn().catch(error); | ||
promiseFunction().catch(error); | ||
``` | ||
@@ -48,0 +48,0 @@ |
'use strict'; | ||
require('./')(); | ||
require('.')(); |
Sorry, the diff of this file is not supported yet
4860
6
25
4