2.2.0 • Published 5 years ago

loud-rejection v2.2.0

Weekly downloads
8,481,794
License
MIT
Repository
github
Last release
5 years ago

loud-rejection Build Status Coverage Status

Make unhandled promise rejections fail loudly instead of the default silent fail

By default, promises fail silently if you don't attach a .catch() handler to them.

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. Not needed in the browser as unhandled rejections are shown in the console.

Install

$ npm install loud-rejection

Usage

const loudRejection = require('loud-rejection');
const promiseFunction = require('promise-fn');

// Install the `unhandledRejection` listeners
loudRejection();

promiseFunction();

Without this module it's more verbose and you might even miss some that will fail silently:

const promiseFunction = require('promise-fn');

function error(error) {
	console.error(error.stack);
	process.exit(1);
}

promiseFunction().catch(error);

Register script

Alternatively to the above, you may simply require loud-rejection/register and the unhandledRejection listener will be automagically installed for you.

This is handy for ES2015 imports:

import 'loud-rejection/register';

API

loudRejection(log)

log

Type: Function Default: console.error

Custom logging function to print the rejected promise. Receives the error stack.

Related

  • hard-rejection - Make unhandled promise rejections fail hard right away instead of the default silent fail
  • More…

archetype-librarybit-bincordovachinjowwchinjowreact-native-bluetooth2killi8n-react-native-fast-image@arisageha/react-lazyloadairscanairscan-examplebb-chatreact-native-esc-pos-sahaab@borisovart/atol-kkt-module@frxf/frxflooopsdeneme323112@ntt_app/react-native-custom-notificationcthpb-plugin-social@olivervorasai/sliderpanqibaounblock-block-save-variables@infinitebrahmanuniverse/nolb-lou@saaspe/components@everything-registry/sub-chunk-2104@frctl/cli@gachou/testdatawc-starterkitwebpack-commandwebpack-serve-node6yraf@geeky-apo/react-native-advanced-clipboardwinx-form-winxwithhold-message-avayarn-fathybyarnpkgyarn-zeovue-prettiervue-dev-clonevue-compmentvideo-multi-uploader@hemith/react-native-tnk@greminder/bootstrap-material-design@google/claspfn-lib-examplesemcomshepspace-hogsspeedlinetest-exhibit-plugintailwind-vector-effecttechpacket-build-toolssyarnstart-starwars-libstripe-donationstandard-commitstandard-commit-2sindresorhus.jstexelsg-buildswarmertwine-libtwine-librarytwitbot-clitweetlite-clits-string-functionsuploadrvcloudcam-playkit-js-hlsws-minerwoofwoof@juturu/yarn@ko-developerhong/react-native-multiple-image-picker@kristoffertonning/vue-laravel-errors@lego-js/testsfastyarnfetpfenglin-uploaderfhir2@horizr/cli@houshuang/yarneasyplayer-myebit-bin@humanmade/cliglit@moezx/meting@morlay/ava@movinliao/mlb@movinliao/mlc@movinliao/mlt@officr/clifreemamba@mgcrea/yarn@mattdesl/fikafinboxio-yarnfind-modified-dependent-filesformatjs-cli-beta-emberformatjs-toolsforked-clasp@maven-io/webpack-servefyarngenerate-serverless-endpoints
2.2.0

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.6.0

8 years ago

1.5.0

8 years ago

1.4.1

8 years ago

1.4.0

8 years ago

1.3.0

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.0

9 years ago