GithubHelp home page GithubHelp logo

explain-error's Introduction

explain-error

wrap errors in explainations.

In node sometimes something fails because of some internal detail, but then this error may be passed back somewhere else, too often, context is lost.

example

var explain = require('explain-error')

//stat a file that does not exist. this will error, add an explaination.
function explainedError(cb) {
  require('fs').stat('neoatuhrcoahkrcophkr', function (err) {
    if(err) cb(explain(err, 'asked for a file that certainly did not exist'))
    else cb()
  })
}

//show that this works even with multiple layers of explainations.
explainedError(function (err) {
  throw explain(err, 'called an function that was expected to fail')
})

output:

fs.stat does not show where it was called from, but at least now you know what happened after that.

Error: called an function that was expected to fail
    at /home/dominic/c/explain-error/example.js:11:9
    at /home/dominic/c/explain-error/example.js:5:13
  Error: asked for a file that certainly did not exist
    at /home/dominic/c/explain-error/example.js:5:16
    at Object.oncomplete (fs.js:107:15)
  Error: ENOENT, stat neoatuhrcoahkrcophkr

parsing stack traces

of course, this adds lines to your errors that will do not look like normal js errors. will this break all your tools? if so please post an issue.

License

MIT

explain-error's People

Contributors

dominictarr 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.