npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

error-stamp

v0.0.5

Published

Mutate an Error object to include a stamp of current step

Downloads

1

Readme

error-stamp Build Status

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.