error-stack-handler

0.0.1 • Public • Published

error-stack-handler

trace the error call stack, filter the unconcerned system call stack and node_modules locations, locate the location of error happened in the project

install

npm install error-stack-handler --save

Usage

require('error-stack-handler')

before

{ Error: Could not find user
    at E:\someproject\node_modules\leancloud-storage\dist\node\request.js:163:17
    at tryCatch (E:\someproject\node_modules\es6-promise\dist\es6-promise.js:410:12)
    at invokeCallback (E:\someproject\node_modules\es6-promise\dist\es6-promise.js:425:13)
    at publish (E:\someproject\node_modules\es6-promise\dist\es6-promise.js:399:7)
    at publishRejection (E:\someproject\node_modules\es6-promise\dist\es6-promise.js:340:3)
    at flush (E:\someproject\node_modules\es6-promise\dist\es6-promise.js:128:5)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickDomainCallback (internal/process/next_tick.js:218:9)

after

{ Error: Could not find user.
    at UserController.login (E:\someproject\somedir\user.js:77:50)
    at UserController.login (E:\someproject\somedir\user.js:77:50)
    at UserController.login (E:\someproject\somedir\user.js:73:28)
    at <anonymous> (E:\someproject\server.js:77:5)

API

The default tracking stack depth is 50, error information at the nodecore and node_modules locations are filtered, and the following API is provided if you need to configure it yourself

const esh = require('error-stack-handler')

// default true, set false will remove nodemoduleFilter from handler chain
esh.enableNodemoduleFilter = {boolean}

// default true, set false will remove nodecoreFilter from handler chain
esh.enableNodecoreFilter = {boolean}

// tracking stack depth,default 50
esh.traceLimit = {number}

// custom error message formatting, frames is an array of CallSite objects, view CallSite API on the V8 stack trace document
esh.formater = function(error, frames)

// appen a handler to the end of handler chain
esh.appendHandler(function(error, frames))

// put a handler to the start of handler chain
esh.prependHandler(function(error, frames))

// remove handler
esh.removeHandler(function)

Example

default

require('error-stack-handler')

custom

const esh = require('error-stack-handler')

esh.enableNodecoreFilter = false
esh.enableNodemoduleFilter = false
esh.appendHandler((err, frames) => {
    return frames.filter(function(callSite){
        const name = callSite && callSite.getFileName();
        return name && !name.includes('E:\\')
    })
})

Readme

Keywords

Package Sidebar

Install

npm i error-stack-handler

Weekly Downloads

1

Version

0.0.1

License

ISC

Unpacked Size

6.94 kB

Total Files

3

Last publish

Collaborators

  • fuguohong