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

@stack-tools/v8-tools

v0.2.4

Published

Tools for printing and parsing v8 errors and their stacks

Downloads

6

Readme

@stack-tools/v8-tools

v8-tools provides utilites for printing and parsing v8 errors and their stacks. If you're not sure if your code will always run in a v8 environment, you will need to know before you use this tool to parse errors. If you are not sure, you should instead use the stack-tools package. Errors that can be parsed by this package will look more or less like this:

Error: A message about the error
    at someFunction (foo.js:10:2)
    at index.js:1:1

What uses v8?

v8 is used in many common browsers including including Chrome, Chromium, IE Edge, and Opera, as well as in node. If you are using node however, you should actually use the node-tools package.

The most notable browsers not using v8 are Firefox (using Spidermonkey) and Safari (using JavaScriptCore).

Usage

import {
  parseErrors,
  cleanErrors,
  printErrors,
} from '@stack-tools/v8-tools';

try {
  doStuff();
} catch (e) {
  const errors = parseErrors(e);

  cleanErrors(errors);

  console.error(printErrors(errors));
}

API

The api for node-tools extends from the stack-tools API. It is capable of more robust parsing though, and can even parse error strings, i.e. parseError(err.stack), which the base stack-tools cannot. Furthermore it provides the most detailed output it can, specifically offering a FrameNode describing content of each frame. When parsing ErrorNode.frames will be an Array<FrameNode>. For details of the AST structure please read ast.d.ts.

v8-tools overrides the implementations of some methods from the stack-tools API to provide support for custom chaining prefixes. Custom prefixes are usually the result of user tampering with error.stack, such as is done by nested-error-stacks.

  • printErrors(error) returns `${printError(error)}\n${error.prefix}: ${printErrors(error.cause)}`

v8-tools also defines the following additional methods:

  • parseFrame(frame) returns a FrameNode
  • isInternalFrame(frame) returns true if frame represents a location internal to the v8 runtime.
  • cleanError(error, predicate = isInternalFrame) mutates error.stack, filtering out internal frames. Returns error.
  • cleanErrors(errors, predicate = isInternalFrame) for each error mutates error.stack, filtering out internal frames. Returns errors.