# nested-error-stacks

> An Error subclass that will chain nested Errors and dump nested stacktraces

Latest version **2.1.1** (published 2022-03-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install nested-error-stacks
pnpm add nested-error-stacks
yarn add nested-error-stacks
bun add nested-error-stacks
```

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2022-03-28 |
| First published | 2014-04-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/nested-error-stacks) |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 93 |
| Author | Matt Lavin |
| Maintainers | mdlavin |
| Keywords | error, nested, stack |

## Links

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

## 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.1.1 (latest) — 2022-03-28
- 2.1.0 — 2018-08-13
- 2.0.1 — 2018-05-23
- 2.0.0 — 2016-11-09
- 1.0.2 — 2015-11-20
- 1.0.1 — 2015-07-17
- 1.0.0 — 2015-04-02
- 0.0.5 — 2015-03-30
- 0.0.4 — 2015-03-17
- 0.0.3 — 2014-04-18
- 0.0.2 — 2014-04-17
- 0.0.1 — 2014-04-17

## README

Nested stacktraces for Node.js!
===============================

[![Build Status](https://github.com/mdlavin/nested-error-stacks/actions/workflows/test.yaml/badge.svg)](https://github.com/mdlavin/nested-error-stacks/actions?query=branch%3Amaster)
[![NPM version](https://badge.fury.io/js/nested-error-stacks.svg)](http://badge.fury.io/js/nested-error-stacks)

With this module, you can wrap a caught exception with extra context
for better debugging.  For example, a network error's stack would normally look
like this:

    Error: connect ECONNREFUSED
        at errnoException (net.js:904:11)
        at Object.afterConnect [as oncomplete] (net.js:895:19)

Using this module, you can wrap the Error with more context to get a stack
that looks like this:

    NestedError: Failed to communicate with localhost:8080
        at Socket.<anonymous> (/Users/mattlavin/Projects/nested-stacks/demo.js:6:18)
        at Socket.EventEmitter.emit (events.js:95:17)
        at net.js:440:14
        at process._tickCallback (node.js:415:13)
    Caused By: Error: connect ECONNREFUSED
        at errnoException (net.js:904:11)
        at Object.afterConnect [as oncomplete] (net.js:895:19)

How to wrap errors
------------------

Here is an example program that uses this module to add more context to errors:

```js
var NestedError = require('nested-error-stacks');
var net = require('net');
    
var client = net.connect({port: 8080});
client.on('error', function (err) {
    var newErr = new NestedError("Failed to communicate with localhost:8080", err);
    console.log(newErr.stack);
});
```

How to inherit
--------------

It is recommended to use explicit names for Error classes. You can do it
like this:

```js
var util = require('util');
var NestedError = require('nested-error-stacks');

function MyError(message, nested) {
    NestedError.call(this, message, nested);
}

util.inherits(MyError, NestedError);
MyError.prototype.name = 'MyError';
```

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