Socket
Socket
Sign inDemoInstall

loud-rejection

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loud-rejection - npm Package Compare versions

Comparing version 1.6.0 to 2.0.0

index.d.ts

33

index.js
'use strict';
var util = require('util');
var onExit = require('signal-exit');
var currentlyUnhandled = require('currently-unhandled');
const util = require('util');
const onExit = require('signal-exit');
const currentlyUnhandled = require('currently-unhandled');
var installed = false;
let installed = false;
module.exports = function (log) {
const loudRejection = (log = console.error) => {
if (installed) {

@@ -15,19 +15,17 @@ return;

log = log || console.error;
const listUnhandled = currentlyUnhandled();
var listUnhandled = currentlyUnhandled();
onExit(() => {
const unhandledRejections = listUnhandled();
onExit(function () {
var unhandledRejections = listUnhandled();
if (unhandledRejections.length > 0) {
unhandledRejections.forEach(function (x) {
var err = x.reason;
for (const unhandledRejection of unhandledRejections) {
let error = unhandledRejection.reason;
if (!(err instanceof Error)) {
err = new Error('Promise rejected with value: ' + util.inspect(err));
if (!(error instanceof Error)) {
error = new Error(`Promise rejected with value: ${util.inspect(error)}`);
}
log(err.stack);
});
log(error.stack);
}

@@ -38,1 +36,4 @@ process.exitCode = 1;

};
module.exports = loudRejection;
module.exports.default = loudRejection;
{
"name": "loud-rejection",
"version": "1.6.0",
"description": "Make unhandled promise rejections fail loudly instead of the default silent fail",
"license": "MIT",
"repository": "sindresorhus/loud-rejection",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "xo && nyc ava",
"coveralls": "nyc report --reporter=text-lcov | coveralls"
},
"files": [
"index.js",
"register.js",
"api.js"
],
"keywords": [
"promise",
"promises",
"unhandled",
"uncaught",
"rejection",
"loud",
"fail",
"catch",
"throw",
"handler",
"exit",
"debug",
"debugging",
"verbose"
],
"dependencies": {
"currently-unhandled": "^0.4.1",
"signal-exit": "^3.0.0"
},
"devDependencies": {
"ava": "*",
"bluebird": "^3.0.5",
"coveralls": "^2.11.4",
"delay": "^1.0.0",
"execa": "^0.4.0",
"get-stream": "^2.0.0",
"nyc": "^6.2.1",
"xo": "*"
},
"nyc": {
"exclude": [
"fixture.js"
]
}
"name": "loud-rejection",
"version": "2.0.0",
"description": "Make unhandled promise rejections fail loudly instead of the default silent fail",
"license": "MIT",
"repository": "sindresorhus/loud-rejection",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && nyc ava && tsd-check"
},
"files": [
"index.js",
"index.d.ts",
"register.js"
],
"keywords": [
"promise",
"promises",
"unhandled",
"uncaught",
"rejection",
"loud",
"fail",
"catch",
"throw",
"handler",
"exit",
"debug",
"debugging",
"verbose"
],
"dependencies": {
"currently-unhandled": "^0.4.1",
"signal-exit": "^3.0.2"
},
"devDependencies": {
"ava": "^1.3.1",
"bluebird": "^3.5.3",
"coveralls": "^3.0.3",
"delay": "^4.1.0",
"execa": "^1.0.0",
"get-stream": "^5.0.0",
"nyc": "^13.3.0",
"tsd-check": "^0.5.0",
"xo": "^0.24.0"
},
"nyc": {
"exclude": [
"fixture.js"
]
}
}

@@ -7,4 +7,6 @@ # loud-rejection [![Build Status](https://travis-ci.org/sindresorhus/loud-rejection.svg?branch=master)](https://travis-ci.org/sindresorhus/loud-rejection) [![Coverage Status](https://coveralls.io/repos/github/sindresorhus/loud-rejection/badge.svg?branch=master)](https://coveralls.io/github/sindresorhus/loud-rejection?branch=master)

This tool keeps track of unhandled rejections globally. If any remain unhandled at the end of your process, it logs them to STDERR and exits with code 1.
Use this in top-level things like tests, CLI tools, apps, etc, **but not in reusable modules.**<br>
Not needed in the browser as unhandled promises are shown in the console.
Not needed in the browser as unhandled rejections are shown in the console.

@@ -15,3 +17,3 @@

```
$ npm install --save loud-rejection
$ npm install loud-rejection
```

@@ -24,8 +26,8 @@

const loudRejection = require('loud-rejection');
const promiseFn = require('promise-fn');
const promiseFunction = require('promise-fn');
// Install the unhandledRejection listeners
// Install the `unhandledRejection` listeners
loudRejection();
promiseFn();
promiseFunction();
```

@@ -36,10 +38,10 @@

```js
const promiseFn = require('promise-fn');
const promiseFunction = require('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);
```

@@ -70,4 +72,10 @@

## Related
- [hard-rejection](https://github.com/sindresorhus/hard-rejection) - Make unhandled promise rejections fail hard right away instead of the default silent fail
- [More…](https://github.com/sindresorhus/promise-fun)
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)
'use strict';
require('./')();
require('.')();

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc