Initial commit
[yaffs-website] / node_modules / loud-rejection / readme.md
1 # 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)
2
3 > Make unhandled promise rejections fail loudly instead of the default [silent fail](https://gist.github.com/benjamingr/0237932cee84712951a2)
4
5 By default, promises fail silently if you don't attach a `.catch()` handler to them.
6
7 Use this in top-level things like tests, CLI tools, apps, etc, **but not in reusable modules.**<br>
8 Not needed in the browser as unhandled promises are shown in the console.
9
10
11 ## Install
12
13 ```
14 $ npm install --save loud-rejection
15 ```
16
17
18 ## Usage
19
20 ```js
21 const loudRejection = require('loud-rejection');
22 const promiseFn = require('promise-fn');
23
24 // Install the unhandledRejection listeners
25 loudRejection();
26
27 promiseFn();
28 ```
29
30 Without this module it's more verbose and you might even miss some that will fail silently:
31
32 ```js
33 const promiseFn = require('promise-fn');
34
35 function error(err) {
36         console.error(err.stack);
37         process.exit(1);
38 }
39
40 promiseFn().catch(error);
41 ```
42
43 ### Register script
44
45 Alternatively to the above, you may simply require `loud-rejection/register` and the unhandledRejection listener will be automagically installed for you.
46
47 This is handy for ES2015 imports:
48
49 ```js
50 import 'loud-rejection/register';
51 ```
52
53
54 ## API
55
56 ### loudRejection([log])
57
58 #### log
59
60 Type: `Function`<br>
61 Default: `console.error`
62
63 Custom logging function to print the rejected promise. Receives the error stack.
64
65
66 ## License
67
68 MIT © [Sindre Sorhus](https://sindresorhus.com)