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
2
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.

  • 2.0.0-main.8668b8f
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11K
increased by17.44%
Maintainers
2
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.

Breaking changes

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).

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

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

await 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.

Keywords

FAQs

Package last updated on 31 May 2024

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