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

async-error-stack

v0.1.1

Published

For better error stacks in async code.

Downloads

5

Readme

Async Error Stack

For better error stacks in async code.

Motivation

Problems I want to solve:

  1. By default, err stack is limited to 10 lines.
  2. the event loop's stack frame context is not maintained in err stacks.
  3. the async module clutters up err stacks.

Problem #2 is seen in this:

const async = require('async');

async.series({
    one: function (callback) {
        setTimeout(function () {
            callback(null, 1);
        }, 200);
    },
    two: function (callback) {
        setTimeout(function () {
            callback(new Error('BOOM!'));
        }, 100);
    }
}, function (err, results) {
    if (err) return void console.error(err);
    /*
    Error: BOOM!
        at Timeout._onTimeout (/Users/zacharyryansmith/Code/sandbox/index.js:26:22)
        at ontimeout (timers.js:475:11)
        at tryOnTimeout (timers.js:310:5)
        at Timer.listOnTimeout (timers.js:270:5)
    */
});

This lib uses longjohn to solve problems #2 and #3, and own code to solve #1:

STACK FILTERED BY !line.includes('node_modules/async/')
Error: BOOM!
    at Timeout.<anonymous> (/Users/zacharyryansmith/Code/sandbox/index.js:35:22)
    at ontimeout (timers.js:475:11)
    at tryOnTimeout (timers.js:310:5)
    at Timer.listOnTimeout (timers.js:270:5)
---------------------------------------------
    at two (/Users/zacharyryansmith/Code/sandbox/index.js:34:9)
    at Timeout.<anonymous> (/Users/zacharyryansmith/Code/sandbox/index.js:30:13)
    at ontimeout (timers.js:475:11)
---------------------------------------------
    at one (/Users/zacharyryansmith/Code/sandbox/index.js:29:9)
    at Object.<anonymous> (/Users/zacharyryansmith/Code/sandbox/index.js:27:7)
---------------------------------------------
FULL STACK
---------------------------------------------
Error: BOOM!
    at Timeout.<anonymous> (/Users/zacharyryansmith/Code/sandbox/index.js:35:22)
    at ontimeout (timers.js:475:11)
    at tryOnTimeout (timers.js:310:5)
    at Timer.listOnTimeout (timers.js:270:5)
---------------------------------------------
    at two (/Users/zacharyryansmith/Code/sandbox/index.js:34:9)
    at /Users/zacharyryansmith/Code/sandbox/node_modules/async/dist/async.js:3866:24
    at replenish (/Users/zacharyryansmith/Code/sandbox/node_modules/async/dist/async.js:998:17)
    at iterateeCallback (/Users/zacharyryansmith/Code/sandbox/node_modules/async/dist/async.js:983:17)
    at /Users/zacharyryansmith/Code/sandbox/node_modules/async/dist/async.js:958:16
    at /Users/zacharyryansmith/Code/sandbox/node_modules/async/dist/async.js:3871:13
    at Timeout.<anonymous> (/Users/zacharyryansmith/Code/sandbox/index.js:30:13)
    at ontimeout (timers.js:475:11)
---------------------------------------------
    at one (/Users/zacharyryansmith/Code/sandbox/index.js:29:9)
    at /Users/zacharyryansmith/Code/sandbox/node_modules/async/dist/async.js:3866:24
    at replenish (/Users/zacharyryansmith/Code/sandbox/node_modules/async/dist/async.js:998:17)
    at /Users/zacharyryansmith/Code/sandbox/node_modules/async/dist/async.js:1002:9
    at eachOfLimit (/Users/zacharyryansmith/Code/sandbox/node_modules/async/dist/async.js:1027:24)
    at /Users/zacharyryansmith/Code/sandbox/node_modules/async/dist/async.js:1032:16
    at _parallel (/Users/zacharyryansmith/Code/sandbox/node_modules/async/dist/async.js:3865:5)
    at Object.series (/Users/zacharyryansmith/Code/sandbox/node_modules/async/dist/async.js:4721:5)
    at Object.<anonymous> (/Users/zacharyryansmith/Code/sandbox/index.js:27:7)

Production Use

Not recommended for use in production, so you can disable it by setting process.env.ASYNC_ERROR_STACK=0 or passing in @disable.

This uses longjohn, which states:

"Longjohn collects a large amount of data in order to provide useful stack traces. While it is very helpful in development and testing environments, it is not recommended to use longjohn in production. The data collection puts a lot of strain on V8's garbage collector and can greatly slow down heavily-loaded applications."

Installation

$ npm install async-error-stack

Usage

const async = require('async');
// How to require:
const errStackLib = require('async-error-stack');

// Can also disable by setting process.env.ASYNC_ERROR_STACK=0.
// @disable overrides process.env.ASYNC_ERROR_STACK.
const { addCleanStack, ERR } = errStackLib({
    disable: process.env.NODE_ENV === 'production',
    logger: console /* console is default */
});

async.series({
    one: function (callback) {
        setTimeout(function () {
            callback(null, 1);
        }, 200);
    },
    two: function (callback) {
        setTimeout(function () {
            callback(new Error('BOOM!'));
        }, 100);
    }
}, function (err, results) {
    // Example use of ERR.
    // If err, then calls console.error(err) using @logger (which defaults to console).
    // if (ERR(err)) return;
    if (err) {
        addCleanStack(err);
        console.error(err);
    }
});