Socket
Socket
Sign inDemoInstall

bugsy

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bugsy

Helper to deal with errors lifecycle in javascript


Version published
Weekly downloads
9
increased by28.57%
Maintainers
1
Weekly downloads
 
Created
Source

bugsy NPM version Build Status ESLint Config

Helper to deal with errors lifecycle in javascript.

Dealing with errors is a common problem in every small or large project. While a lot of libraries simply focus on their creation, this library is meant to deal with their lifecycle.

Features

  • Universal module
  • Error severity
  • Custom metadata
  • Flowtype

Installation

NPM

With NPM:

$ npm install bugsy

With Yarn:

$ yarn add bugsy

Usage

import * as bugsy from 'bugsy';

const RAN_AWAY = 'ran_away';
const THROW_MISSED = 'throw_missed';

const ranAway = bugsy.createError(RAN_AWAY, 'It ran away, again');
const throwMissed = bugsy.createError(THROW_MISSED, 'Throw totally missed');

function capture() {
  const r = Math.random();

  if (r < 0.3) {
    throw throwMissed({ severity: bugsy.syslog.WARNING });
  } else if (r < 0.6) {
    throw ranAway();
  } else {
    throw new Error();
  }
}

function handler(fn) {
  try {
    fn();
  } catch (err) {
    console.log(bugsy.toString(err));
  }
}

handler(() => {
  try {
    capture();
  } catch (err) {
    switch (err.code) {
      case THROW_MISSED:
        console.log('Oh well...');
        break;
      case RAN_AWAY:
        throw err.setSeverity(bugsy.syslog.CRITICAL).addMeta({ firstTry: true });
      default:
        throw bugsy.convert(err).setSeverity(bugsy.syslog.EMERGENCY);
    }
  }
});

Licences

njakob/bugsy is licensed under the MIT License.

Keywords

FAQs

Package last updated on 14 Jan 2017

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