2.1.1 • Published 2 years ago

nested-error-stacks v2.1.1

Weekly downloads
2,507,300
License
MIT
Repository
github
Last release
2 years ago

Nested stacktraces for Node.js!

Build Status NPM version

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:

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:

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';
cp-file@nicoandmee/bt_backend-core@bent10/codepcodep@infinitebrahmanuniverse/nolb-neste@saaspe/components@everything-registry/sub-chunk-2257design-system-fitbank-450errors-blueforestepic-kafka-nodedgty-kafka-nodefn-lib-examplefast-objectfeline-typescript-iskicad-library-manager-commonjasmine-node-promise-matchersgoogle-finance-datahtml-reportergen-cli-for-docsifykafka-node-oauthkafka-node-sidvkafka-nodekafka-node-als-clonekafka-for-nodehermione-headless-chrome@jellywelly/iterare@hypnosphi/html-reporterneoman-engine@iota-fork/kafka-nodemega-kafka-node@jdxcode/cpy@lego-js/testsmovie-list@kicad-library-manager/cli@kicad-library-manager/common@lifeomic/lambda-toolsmicro-req@hoanghuy/kafka-nodelooks-samengindoxngrx-undo-v2@epiclabs/kafka-node@perp/common@pefish/kafka-node@player-ui/bindingpango-git-version@pleisto/cpypangopango-gcc@podlubnaja/ui-kitparvan_componentsparvan_reactjs_componentspi-stm32-uart-bootloader@pubkeeper/protocol-legacy@pubkeeper/protocol-v1@pubkeeper/protocol-v1-1@pubkeeper/client@saperiuminc/saperium-kafka-node@nxtedition/lib@rstacruz/pnpmrequiregrequireg-extasync-response-aggregator-serversequelcomponent@blkmarketco/components-librarysimple-repositorysimple-kerberossimple-ldapjs@zalastax/nolb-neste@arkntools/unity-jsappcharge-checkoutappcharge-checkout-reactjs-sdksecuretransport-files@testplane/headless-chrome@xinghunm/fs@xinghunm/require@skedulr/nebula-ui-library@skeetboothppq/component-libraryreact-form-component-library@vitali_shcherbina/styled-lib@shivarajapple/first-libraryrm-filesvelte-component-lib@detachhead/typescript-isthesaurus-serviceconfigurapiqgenteraslice-workertedicloud-linkcm-janus@brickdoc/cpy@cjsa/cpy@ckitching/typescript-isbirken-react-native-community-image-editorboxhock_google-finance-data@denali-js/clitldrawlignincpy-synctypescript-is
2.1.1

2 years ago

2.1.0

6 years ago

2.0.1

6 years ago

2.0.0

7 years ago

1.0.2

8 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago