Git Product home page Git Product logo

errsome's Introduction

errsome

Making errors more loggable, readable and serializable, but still object.

Build Status NPM version

Why?

There is some problems with Error object in node.js, so why not try to handle it?

Synopsis

~/js/github/errsome $ node
> const errsome = require('.')
undefined
> const err = new TypeError('This is a message\nMulti line')
undefined
> err.field = 'bla'
'bla'
> err
{ TypeError: This is a message
Multi line
    at repl:1:13
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at REPLServer.defaultEval (repl.js:239:29)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at REPLServer.onLine (repl.js:440:10)
    at emitOne (events.js:120:20)
    at REPLServer.emit (events.js:210:7)
    at REPLServer.Interface._onLine (readline.js:282:10)
    at REPLServer.Interface._line (readline.js:631:8) field: 'bla' }
> errsome(err)
{ name: 'TypeError',
  message: ['This is a message', 'Multi line'],
  stack:
   [ 'at repl:1:13',
     'at ContextifyScript.Script.runInThisContext (vm.js:50:33)',
     'at REPLServer.defaultEval (repl.js:239:29)',
     'at bound (domain.js:301:14)',
     'at REPLServer.runBound [as eval] (domain.js:314:12)',
     'at REPLServer.onLine (repl.js:440:10)',
     'at emitOne (events.js:120:20)',
     'at REPLServer.emit (events.js:210:7)',
     'at REPLServer.Interface._onLine (readline.js:282:10)',
     'at REPLServer.Interface._line (readline.js:631:8)' ],
  field: 'bla' }
>

Install

npm i errsome

Usage

const errsome = require('errsome');

const err = new Error('Bla-bla-bla');

const awesomeError = errsome(err);

const serializedError = errsome.stringify(err, 2);
// It is just a short form for this:
// require('json5').stringify(err, null, 2);

errsome.log(err, 2);
// It is just a short form for this:
// console.log(errsome.stringify(err, 2));

License

MIT

errsome's People

Contributors

astur avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.