Socket
Socket
Sign inDemoInstall

bugsy

Package Overview
Dependencies
0
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    bugsy

Helper to deal with errors lifecycle in javascript


Version published
Maintainers
1
Created

Readme

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.createDynamicError(RAN_AWAY, (name) => `${name} ran away, again`);
const throwMissed = bugsy.createError(THROW_MISSED, 'Throw totally missed');

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

  if (r < 0.3) {
    throw throwMissed();
  } else if (r < 0.6) {
    throw ranAway(name);
  } else {
    throw new Error();
  }
}

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

handler(() => {
  try {
    capture('Abra');
  } 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

Last updated on 12 Feb 2017

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