Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

error-stamp

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

error-stamp

Mutate an Error object to include a stamp of current step

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

error-stamp [![Build Status][ci-img]][ci]

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 ERR = require('errorStamp');

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

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

var ERR = require('errorStamp');

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

Before & After

Before using the module

node example.js

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

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

After using the module

node example_withstamps.js

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

Error
    at ErrStamp /tmp/error-stamp/example_withstamps.js:7:23
    at ErrStamp /tmp/error-stamp/example_withstamps.js:22:26
    at null._onTimeout (/tmp/error-stamp/example_withstamps.js:35:18)
    at Timer.listOnTimeout (timers.js:89:15)

API

errorStamp(err)

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

Parameters

err: Error, an object that inherits from Error.prototype

errorStamp.setErrorPrefix(value)

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

Parameters

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

Keywords

FAQs

Package last updated on 14 Jul 2016

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