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

on-error-resume-next

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

on-error-resume-next

Run a function, synchronously or asynchronously, and ignore errors.

  • 1.0.1-master.589b356
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11K
increased by17.44%
Maintainers
1
Weekly downloads
 
Created
Source

on-error-resume-next

Run a function, synchronously or asynchronously, and ignore errors.

npm version Build Status

The name come from Visual Basic. The original On Error Resume Next statement is considered a bad error handling practice.

Although the perception of the feature is negative, when scoped and used responsibly, it can become a very helpful utility function.

Usage

onErrorResumeNext will return the result if it is a success. For example,

import onErrorResumeNext from 'on-error-resume-next';

const text = '{"hello":"World!"}';
const parsed = onErrorResumeNext(() => JSON.parse(text));

expect(parsed).toEqual({ hello: 'World!' });

Otherwise, it will return undefined,

const parsed = onErrorResumeNext(() => JSON.parse('<xml />'));

expect(parsed).toBeUndefined();

When using onErrorResumeNext, please be responsible and fully understand the impact of ignoring errors.

Asynchronous using async/await

onErrorResumeNext will capture both exceptions (synchronous) and rejections (asynchronous). It is recommended to pair up with await keyword to handle both cases in the same way.

const res = await onErrorResumeNext(() => fetch('/health'));

expect(res).toBeUndefined();

The code is for elaboration only, the better expectation should be expect(res).resolves.toBeUndefined().

Contributions

Like us? Star us.

Want to make it better? File us an issue.

Don't like something you see? Submit a pull request.

FAQs

Package last updated on 19 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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