Git Product home page Git Product logo

error-stamp's Introduction

error-stamp

Build status Test coverage Downloads

Mutate a JS error object to include a stamp of current step.

Why

The main motivation for this module is for using Node.JS style callbacks. When passing the Error object, it contains the details of the sync call, but loses track of all async coming after.

This module solves this issue by adding to the trace additional "stamps" when used. For example, if before you handled errors like this:

if(err) {
    callback(err);
    return;
}   

Now you can get additional trace information by doing:

var stamp = require('error-stamp');

if(err) {
    stamp(err);
    callback(err);
    return;
}   

And since the function always return the input, there's a shorter version:

var stamp = require('error-stamp');

if(err) {
    callback(stamp(err));
    return;
}   

Before & After

Before using the module

node examples/example.js

/tmp/error-stamp/examples/example.js:42
        throw err;
        ^

Error
    at null._onTimeout (/tmp/error-stamp/examples/example.js:35:18)
    at Timer.listOnTimeout (timers.js:89:15)

After using the module

node examples/example_withstamps.js

/tmp/error-stamp/examples/example_withstamps.js:42
        throw err;
        ^

Error
    at ErrStamp /tmp/error-stamp/examples/example_withstamps.js:8:33
    at ErrStamp /tmp/error-stamp/examples/example_withstamps.js:23:36
    at null._onTimeout (/tmp/error-stamp/examples/example_withstamps.js:35:18)
    at Timer.listOnTimeout (timers.js:89:15)

API

errorStamp(err, [msg])

Mutate an Error object to include a stamp of current step.

Kind: global function

Param Type Description
err Error An object that inherits from Error.prototype .
[msg] string Optional. A message to add with the stamp.

errorStamp.setErrorPrefix(value)

Sets the error prefix used in each new line added to the trace. Default is "ErrStamp"

Kind: static method of errorStamp

Param Type Description
value string The value to set

Alternatives

Some other module tackle the same issue, among them:

  • longjohn does the job, but as it has recommended- not intended on production environment (note it interferes with every asyc execution).
  • async-stacktrace has greatly inspired this module, but it does more than just adding trace stamps (throw errors, call callbacks and conditionally create Error objects).

Notes

This module can also be used when handling errors with promises.

error-stamp's People

Contributors

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