-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f77154a
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
coverage/ | ||
node_modules/ | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2019 Gustaf Räntilä | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
[![npm version][npm-image]][npm-url] | ||
[![downloads][downloads-image]][npm-url] | ||
[![build status][travis-image]][travis-url] | ||
[![coverage status][coverage-image]][coverage-url] | ||
[![greenkeeper badge][greenkeeper-image]][greenkeeper-url] | ||
[![Language grade: JavaScript][lgtm-image]][lgtm-url] | ||
|
||
# trace-unhandled | ||
|
||
Node.js warns on unhandled promise rejections. You might have seen: | ||
|
||
``` | ||
(node:1234) UnhandledPromiseRejectionWarning | ||
``` | ||
|
||
When this happens, it's not always obvious what promise is unhandled. The error displayed in the stack trace is the trace to the *error object construction*, not the construction of the promise which left it dangling. It might have travelled through various asynchronous chains before it got to an unhandled promise chain. | ||
|
||
`trace-unhandled` changes this. It keeps track of promises and when an *unhandled promise rejection* is logged, the location of both the error object **and** the promise is logged. This makes it a lot easier to find the bug. | ||
|
||
**This package is not intended to be used in production, only to aid spotting bugs** | ||
|
||
# API | ||
|
||
```ts | ||
require( 'trace-unhandled/register' ); // As early as possible | ||
``` | ||
|
||
or if you want to allow some code to execute before you start tracing: | ||
|
||
```ts | ||
const { register } = require( 'trace-unhandled' ); | ||
|
||
// ... whenever you want to start tracing | ||
register( ); | ||
``` | ||
|
||
|
||
[npm-image]: https://img.shields.io/npm/v/trace-unhandled.svg | ||
[npm-url]: https://npmjs.org/package/trace-unhandled | ||
[downloads-image]: https://img.shields.io/npm/dm/trace-unhandled.svg | ||
[travis-image]: https://img.shields.io/travis/grantila/trace-unhandled/master.svg | ||
[travis-url]: https://travis-ci.org/grantila/trace-unhandled | ||
[coverage-image]: https://coveralls.io/repos/github/grantila/trace-unhandled/badge.svg?branch=master | ||
[coverage-url]: https://coveralls.io/github/grantila/trace-unhandled?branch=master | ||
[greenkeeper-image]: https://badges.greenkeeper.io/grantila/trace-unhandled.svg | ||
[greenkeeper-url]: https://greenkeeper.io/ | ||
[lgtm-image]: https://img.shields.io/lgtm/grade/javascript/g/grantila/trace-unhandled.svg?logo=lgtm&logoWidth=18 | ||
[lgtm-url]: https://lgtm.com/projects/g/grantila/trace-unhandled/context:javascript |