Socket
Socket
Sign inDemoInstall

loud-rejection

Package Overview
Dependencies
Maintainers
1
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.0.0 to 1.1.0

50

index.js
'use strict';
var onExit = require('signal-exit');
var installed = false;
function outputRejectedMessage(err) {
if (err instanceof Error) {
console.error(err.stack);
} else if (typeof err === 'undefined') {
console.error('Promise rejected no value');
} else {
console.error('Promise rejected with value:', err);
}
}
module.exports = function () {
process.on('unhandledRejection', function (err) {
if (err instanceof Error) {
console.error(err.stack);
} else if (err) {
console.error('Promise rejected with value:', err);
} else {
console.error('Promise rejected no value');
}
var unhandledRejections = [];
process.exit(1);
if (installed) {
console.trace('WARN: loud rejection called more than once');
return;
}
installed = true;
process.on('unhandledRejection', function (reason, p) {
unhandledRejections.push({reason: reason, p: p});
});
process.on('rejectionHandled', function (p) {
var index = unhandledRejections.reduce(function (result, item, idx) {
return (item.p === p ? idx : result);
}, -1);
unhandledRejections.splice(index, 1);
});
onExit(function () {
if (unhandledRejections.length > 0) {
unhandledRejections.forEach(function (x) {
outputRejectedMessage(x.reason);
});
process.exitCode = 1;
}
});
};
{
"name": "loud-rejection",
"version": "1.0.0",
"version": "1.1.0",
"description": "Make unhandled promise rejections fail loudly instead of the default silent fail",

@@ -16,3 +16,4 @@ "license": "MIT",

"scripts": {
"test": "node test.js || exit 0"
"test": "xo && nyc ava",
"coveralls": "nyc report --reporter=text-lcov | coveralls"
},

@@ -24,3 +25,5 @@ "files": [

"promise",
"promises",
"unhandled",
"uncaught",
"rejection",

@@ -32,8 +35,32 @@ "loud",

"handler",
"exit"
"exit",
"debug",
"debugging",
"verbose"
],
"dependencies": {
"signal-exit": "^2.1.2"
},
"devDependencies": {
"ava": "*",
"bluebird": "^3.0.5",
"coveralls": "^2.11.4",
"get-stream": "^1.0.0",
"nyc": "^3.2.2",
"xo": "*"
},
"xo": {
"ignores": [
"test.js"
]
},
"config": {
"nyc": {
"exclude": [
"node_modules",
"test.js",
"fixture.js"
]
}
}
}

6

readme.md

@@ -1,2 +0,2 @@

# loud-rejection [![Build Status](https://travis-ci.org/sindresorhus/loud-rejection.svg?branch=master)](https://travis-ci.org/sindresorhus/loud-rejection)
# 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/sindresorhus/loud-rejection/badge.svg?branch=master&service=github)](https://coveralls.io/github/sindresorhus/loud-rejection?branch=master)

@@ -7,7 +7,5 @@ > Make unhandled promise rejections fail loudly instead of the default [silent fail](https://gist.github.com/benjamingr/0237932cee84712951a2)

This is useful for CLI tools so you don't have to manually `.catch()` all the promises.
Use it in top-level things like tests, CLI tools, apps, etc, **but not in reusable modules.**
**Should NOT be used in reusable modules. Only in top-level apps / CLI tools.**
## Install

@@ -14,0 +12,0 @@

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