# @stack-tools/v8-tools

> Tools for printing and parsing v8 errors and their stacks

Latest version **0.2.4** (published 2021-12-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @stack-tools/v8-tools
pnpm add @stack-tools/v8-tools
yarn add @stack-tools/v8-tools
bun add @stack-tools/v8-tools
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.4 |
| Published | 2021-12-04 |
| First published | 2021-12-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 52.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Conrad Buck |
| Maintainers | conartist6 |

## Links

- npm: https://www.npmjs.com/package/@stack-tools/v8-tools
- Repository: https://github.com/stack-tools-js/stack-tools
- Homepage: https://github.com/stack-tools-js/stack-tools#readme
- Issues: https://github.com/stack-tools-js/stack-tools/issues
- npm.io page: https://npm.io/package/@stack-tools/v8-tools

## Dependencies (3)

- [moo](https://npm.io/package/moo.md) ^0.5.1
- [nearley](https://npm.io/package/nearley.md) ^2.20.1
- [stack-tools](https://npm.io/package/stack-tools.md) ^0.2.2

## Recent versions

- 0.2.4 (latest) — 2021-12-04
- 0.2.3 — 2021-12-04
- 0.2.2 — 2021-12-04
- 0.2.1 — 2021-12-04
- 0.2.0 — 2021-12-04
- 0.1.0 — 2021-12-03

## 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](https://github.com/stack-tools-js/stack-tools/tree/trunk/packages/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](https://nodejs.org/). If you are using node however, you should actually use the [node-tools](https://github.com/stack-tools-js/stack-tools/tree/trunk/packages/stack-tools-node) package.

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

## Usage

```js
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](https://github.com/stack-tools-js/stack-tools/tree/trunk/packages/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](https://github.com/stack-tools-js/stack-tools/tree/trunk/packages/stack-tools-v8/lib/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](https://www.npmjs.com/package/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`.

---
_Source: https://npm.io/package/@stack-tools/v8-tools · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
