Socket
Socket
Sign inDemoInstall

errorish

Package Overview
Dependencies
1
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    errorish

When you have an error-ish but what you really want is an Error


Version published
Weekly downloads
2K
decreased by-0.89%
Maintainers
1
Install size
96.1 kB
Created
Weekly downloads
 

Readme

Source

Errorish

Version Build Status Coverage Dependencies Vulnerabilities License Types

When you have an error-ish but what you really want is an Error.

Install

npm install errorish

Use cases

There are three main use cases for Errorish:

Usage

See complete documentation.

  • Exception is an Error extending class with additional label, error and data fields.
  • Utils:
    • ensure ensures any is an Error, otherwise creating one -it can optionally include a normalization step, enabled by default.
    • normalize ensures an Error has a message, name, and stack properties -filling them if they're not defined.
    • capture runs Error.captureStackTrace if running in V8 to clean up the error stack trace.

Exception

See documentation for Exception.

Exception is an Error extending class that can store an identifying label, the source error that caused it and/or additional associated data. Exception also comes with several static and instance methods.

import { Exception } from 'errorish';

try {
  try {
    throw Error('Source');
  } catch(err) {
    // throws with label
    throw new Exception(['label', 'message'], err, { code: 401 });
  }
} catch(err) {
  // throws without label
  throw new Exception(err.message, err, { code: 500 })
}

Utils

ensure

See documentation for ensure.

Ensure will return its first argument if an instance of Error is passed as such, otherwise instantiating and returning an Exception.

import { ensure } from 'errorish';

ensure('foo'); // Error: foo
ensure(Error('foo')); // Error: foo
ensure({ message: 'foo' }); // Error: foo
normalize

See documentation for normalize.

Normalization fills an error's message, name, and stack property when empty. It's performed by default by ensure, but it can also be run independently.

import { normalize } from 'errorish';

normalize(Error()); // Error: An error occurred
normalize(Error(), { message: 'Foo bar' }); // Error: Foo bar
capture

See documentation for capture.

Captures the stack trace on Node and Chromium browsers.

import { capture } from 'errorish';

capture(Error());

Keywords

FAQs

Last updated on 11 Dec 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc