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

extend-stack

v1.1.1

Published

Two util methods `extendStack` and `extendCb` that make it easier to track async errors in callback systems.

Downloads

9

Readme

extend-stack

extend-stack offers two util methods extendStack and extendCb that make it easier to track async errors in callback systems.

Build Status

Installation and Setup

$ npm install extend-stack

extend-stack is disabled by default because it consumes quite a bit of resources to work. To enable it you need enable debug either when calling your code…

$ env DEBUG=extend-stack node myapp.js # mac variant!

…or programmatically − after adding $ npm install debug − like this…

const debug = require('debug')
debug.enable('extend-stack')

Usage

The two methods are exposed as object:

const { extendStack, extendCb } = require('extend-stack')

extendCb(function (err, data) {})function (err, data) {}

extendCb adds the error stack of the calling function in case an error occurs.

const fs = require('fs')

setImmediate(() => {
  fs.readFile('non-existing', extendCb((err) => {
    console.log(err.stack)
  }))
})
Error: ENOENT: no such file or directory, open 'non-existing'
Error: ENOENT: no such file or directory, open 'non-existing'
    at Immediate.setImmediate (/extend-stack/examples/extendCb.js:5:31)
    at runCallback (timers.js:789:20)
    at tryOnImmediate (timers.js:751:5)
    at processImmediate [as _immediateCallback] (timers.js:722:5)

If the error contains a stack, the stack will be part of it:

const { extendCb } = require('..')

function errorProne (cb) {
  setImmediate(() => cb(new Error('sample-error')))
}

function userFunction () {
  errorProne(
    extendCb(err => console.log(err.stack))
  )
}

setImmediate(userFunction)
Error: sample-error
    at Immediate.setImmediate [as _onImmediate] (/extend-stack/examples/extendCb-withStack.js:4:25)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)
Error: sample-error
    at Immediate.userFunction (/extend-stack/examples/extendCb-withStack.js:9:5)
    at runCallback (timers.js:789:20)
    at tryOnImmediate (timers.js:751:5)
    at processImmediate [as _immediateCallback] (timers.js:722:5)
    caused by:
    at Immediate.setImmediate (/extend-stack/examples/extendCb-withStack.js:4:25)
    at runCallback (timers.js:789:20)
    at tryOnImmediate (timers.js:751:5)
    at processImmediate [as _immediateCallback] (timers.js:722:5)

extendStack(err, [offset])Error

extendStack extends the stack stored in err and adds the current line's stack as well.

const { extendStack } = require('..')

function subsystem (err) {
  return extendStack(err)
}

setImmediate(() => {
  const err = subsystem(new Error('some-error'))
  console.log(err)
})
Error: some-error
    at Immediate.setImmediate (/extend-stack/examples/extendStack.js:8:25)
    at runCallback (timers.js:789:20)
    at tryOnImmediate (timers.js:751:5)
    at processImmediate [as _immediateCallback] (timers.js:722:5)
Error: some-error
    at subsystem (/extend-stack/examples/extendStack.js:4:10)
    at Immediate.setImmediate (/extend-stack/examples/extendStack.js:8:15)
    at runCallback (timers.js:789:20)
    at tryOnImmediate (timers.js:751:5)
    at processImmediate [as _immediateCallback] (timers.js:722:5)
    caused by:
    at Immediate.setImmediate (/extend-stack/examples/extendStack.js:8:25)
    at runCallback (timers.js:789:20)
    at tryOnImmediate (timers.js:751:5)
    at processImmediate [as _immediateCallback] (timers.js:722:5)

License

MIT