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

v2.0.4

Published

Extract callsite objects from Error objects

Downloads

1,242,700

Readme

error-callsites

Yet another module for extracting callsites (a.k.a. stack-frames) from Node.js Error objects.

npm Tests js-standard-style

Installation

npm install error-callsites

Usage

var callsites = require('error-callsites')

var err = new Error('foo')
var frames = callsites(err)

console.log('Error occurred on line', frames[0].getLineNumber())

API

The module exposes a single function which expects an Error object as the first argument:

var frames = callsites(err)

More specifically, it expects an object on which Error.captureStackTrace(obj) has been called, which is the case for Error objects. You can do it directly yourself:

var obj = {}
Error.captureStackTrace(obj)
var frames = callsites(err)

The function returns an array of v8 CallSite objects -- one for each frame in the stack trace. CallSite objects provide accessor methods for information on that frame. For example:

  • callsite.getThis() - returns the value of this
  • callsite.getTypeName() - returns the type of this as a string. This is the name of the function stored in the constructor field of this, if available, otherwise the object's [[Class]] internal property.
  • callsite.getFunction() - returns the current function
  • callsite.getFunctionName() - returns the name of the current function, typically its name property. If a name property is not available an attempt will be made to try to infer a name from the function's context.
  • callsite.getMethodName() - returns the name of the property of this or one of its prototypes that holds the current function
  • callsite.getFileName() - if this function was defined in a script returns the name of the script
  • callsite.getLineNumber() - if this function was defined in a script returns the current line number
  • callsite.getColumnNumber() - if this function was defined in a script returns the current column number
  • callsite.getEvalOrigin() - if this function was created using a call to eval returns a CallSite object representing the location where eval was called
  • callsite.isToplevel() - is this a toplevel invocation, that is, is this the global object?
  • callsite.isEval() - does this call take place in code defined by a call to eval?
  • callsite.isNative() - is this call in native V8 code?
  • callsite.isConstructor() - is this a constructor call?

See the link above for a complete list of the accessor methods. Some have been added in more recent versions of v8 and Node.js.

How it works

This package works by setting a custom Error.prepareStackTrace property that transparently captures the structured stack trace that v8 passes to this API, while also supporting other Node.js code in the process setting its own Error.prepareStackTrace.

License

MIT