Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

caught

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

caught - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

fail.js

2

package.json
{
"name": "caught",
"version": "0.0.1",
"version": "0.0.2",
"description": "Avoids UnhandledPromiseRejectionWarning and PromiseRejectionHandledWarning",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -12,6 +12,58 @@ node caught

See this answer on Stack Overflow:
Doing something like this:
* [Should I refrain from handling Promise rejection asynchronously?](https://stackoverflow.com/questions/40920179/should-i-refrain-from-handling-promise-rejection-asynchronously/40921505#40921505)
```js
var p = Promise.reject(0);
setTimeout(() => p.catch(e => console.error('caught')), 0);
```
will generate a lot of helpful warnings:
```
(node:13548) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): 0
(node:13548) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:13548) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1)
```
This module lets you write:
```js
var caught = require('caught');
var p = caught(Promise.reject(0));
setTimeout(() => p.catch(e => console.error('caught')), 0);
```
to avoid those warnings. Use at your own risk.
For more info see this answer on Stack Overflow:
* [**Should I refrain from handling Promise rejection asynchronously?**](https://stackoverflow.com/questions/40920179/should-i-refrain-from-handling-promise-rejection-asynchronously/40921505#40921505)
Installation
------------
To use in your projects:
```sh
npm install caught --save
```
Usage
-----
```js
var caught = require('caught');
var p = caught(Promise.reject(0));
```
Note that it is not the same as writing:
```js
var p = Promise.reject(0).catch(() => {});
```
which would not return the original promise and wouldn't let you to add `catch` handlers later.
Issues

@@ -18,0 +70,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