New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ensure-error

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

ensure-error

Ensures a value is a valid error by making it one if not

  • 4.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17K
decreased by-26.1%
Maintainers
1
Weekly downloads
 
Created
Source

ensure-error

Ensures a value is a valid error by making it one if not

Pass it any value and you're are guaranteed to get back an Error with name, message, and stack properties.

Can be useful when you don't control all the places an error can be thrown or rejected. A user could for example throw a string or an error without a stack property.

Install

$ npm install ensure-error

Usage

import ensureError from 'ensure-error';

const error = new TypeError('🦄');
error.name = '';

console.log(error.name);
//=> ''

console.log(ensureError(error).name);
//=> 'TypeError'
import ensureError from 'ensure-error';

console.log(ensureError(10));
//=> [NonError: 10]

API

ensureError(input)

If input is an Error, any missing Error properties will be added. If it's not an Error, input is converted to an Error.

input

Type: unknown

Keywords

FAQs

Package last updated on 27 Aug 2021

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