2.1.0 • Published 6 years ago

hard-rejection v2.1.0

Weekly downloads
3,789,392
License
MIT
Repository
github
Last release
6 years ago

hard-rejection Build Status

Make unhandled promise rejections fail hard right away instead of the default silent fail

Promises fail silently if you don't attach a .catch() handler.

This module exits the process with an error message right away when an unhandled rejection is encountered. Note: That might not be desirable as unhandled rejections can be handled at a future point in time, although not common. You've been warned.

Intended for top-level long-running processes like servers, but not in reusable modules. For command-line apps and tests, see loud-rejection.

Install

$ npm install hard-rejection

Usage

const hardRejection = require('hard-rejection');
const promiseFunction = require('some-promise-fn');

// Install the handler
hardRejection();

promiseFunction();

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

const promiseFunction = require('some-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 hard-rejection/register and the handler will be automagically installed for you.

This is handy for ES2015 imports:

import 'hard-rejection/register';

API

hardRejection(log)

log

Type: Function Default: console.error

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

Related

License

MIT © Sindre Sorhus

archetype-libraryeasy-select-rnreact-native-bluetooth2killi8n-react-native-fast-imageairscanairscan-examplereact-native-esc-pos-sahaab@borisovart/atol-kkt-module@frxf/frxfdeneme323112@ntt_app/react-native-custom-notificationreact-native-covid-sdk@jttechnic/interpretermysql-formatreact-native-printer-brothersreact-native-shekhar-bridge-testcogoportutils@oiti/documentoscopy-react-native@mink-opn/build-tokensquoc-test@infinitebrahmanuniverse/nolb-hard@saaspe/componentsexpand-react-bridgeopea-bootstraapluminos-ui-core@everything-registry/sub-chunk-1826iqra-calculatorjawwy-sdkjawwy_gamification_releasereact-native-sphereuisphereuijawwy_libraryreact-native-credit-card-pkgreact-native-jawwy_samplelapture-ui-complaptureuigriffin-ui-librarytailwind-vector-effecttest-iki-mini-apptest-library-123test-haptik-libwinx-form-winxweb-elements-iconswifi_configuration_packagexinquirersui-monorepotest-zeo-collectswirlysweetalert2-denazificationvishwanaathh4_dbvishwanaathh4_db1vishwanaathh4_db2vishwanaathh4_dbbvision-camera-plugin-face-detectorvision-camera-plugin-scan-facesvision-camera-base64-resizedvantiq-react@dotconf-pro/dotconf-pro@dotconf-pro/dotenv@cs6/react-native-test-native-view-library@commonshost/cli@commonshost/manifest@commonshost/server@con-test/react-native-concent-common@damruravihara/react-native-testing-package@corelmax/react-native-my2c2p-sdk@praella/localisationist@positionex/position-sdkcauseway-concrete-stylesjahancli_calculatorip-designjrennsoh88-react-native-scroll-indicatorjesh-calculationjetbrains-projectjnf-accesscontrol-rnttljordy-frijters-test-libjamuskalimkeymail-clikhaled-salem-custom-componentsjawwy_library_newjawy_library_v1gamification-jawwy-libraryframework_test_library_sixdee_new_jawwyibraz-calculatortest_lib_module_aardfeuk-frontenddfeuk-frontend-manualquickcapture_react_nativesushi-sdk-ftmrn-agora-ios-m@castrum-nubis/bulmazzzxxxyyy321123react-native-omental-frameworkreact-native-sixdee_test_libstyletoolsspigot-ui-inventorysupreme-bot-by-pksurprize-message123-by-mussarattunneleru-library
2.1.0

6 years ago

2.0.0

6 years ago

1.0.0

8 years ago

0.1.0

9 years ago