# error-callsites

> Extract callsite objects from Error objects

Latest version **2.0.4** (published 2021-06-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install error-callsites
pnpm add error-callsites
yarn add error-callsites
bun add error-callsites
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.4 |
| Published | 2021-06-11 |
| First published | 2015-09-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.x |
| Dependencies | 0 |
| Unpacked size | 8.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Thomas Watson Steen |
| Maintainers | trentm, watson, qard, alanstorm |
| Keywords | v8, error, errors, stack, stacktrace, stacktraces, callsite, callsites, stackframe, stackframes, frames |

## Links

- npm: https://www.npmjs.com/package/error-callsites
- Repository: https://github.com/watson/error-callsites
- Homepage: https://github.com/watson/error-callsites#readme
- Issues: https://github.com/watson/error-callsites/issues
- npm.io page: https://npm.io/package/error-callsites

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 2.0.4 (latest) — 2021-06-11
- 2.0.3 — 2020-03-16
- 2.0.2 — 2019-08-21
- 2.0.1 — 2019-08-21
- 2.0.0 — 2019-08-21
- 1.0.1 — 2016-10-27
- 1.0.0 — 2015-09-02

## README

# error-callsites

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

[![npm](https://img.shields.io/npm/v/error-callsites.svg)](https://www.npmjs.com/package/error-callsites)
[![Tests](https://github.com/watson/error-callsites/workflows/Tests/badge.svg)](https://github.com/watson/error-callsites/actions)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)

## Installation

```
npm install error-callsites
```

## Usage

```js
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:

```js
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:

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

The function returns an array of
[v8 `CallSite` objects](https://v8.dev/docs/stack-trace-api#customizing-stack-traces)
-- 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`](https://v8.dev/docs/stack-trace-api#customizing-stack-traces)
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](LICENSE)

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