Coder Social home page Coder Social logo

extract-stack's Introduction

extract-stack

Extract the actual stack of an error

Install

$ npm install extract-stack

Usage

import extractStack from 'extract-stack';

const error = new Error('Missing unicorn');

console.log(error.stack);
/*
Error: Missing unicorn
    at Object.<anonymous> (/Users/sindresorhus/dev/extract-stack/unicorn.js:2:15)
    at Module._compile (module.js:409:26)
    at Module.load (module.js:343:32)
    at startup (node.js:139:18)
*/

console.log(extractStack(error));
/*
    at Object.<anonymous> (/Users/sindresorhus/dev/extract-stack/unicorn.js:2:15)
    at Module._compile (module.js:409:26)
    at Module.load (module.js:343:32)
    at startup (node.js:139:18)
*/

console.log(extractStack.lines(error));
/*
[
	'Object.<anonymous> (/Users/sindresorhus/dev/extract-stack/unicorn.js:2:15)'
	'Module._compile (module.js:409:26)'
	'Module.load (module.js:343:32)'
	'startup (node.js:139:18)'
]
*/

API

It gracefully handles cases where the stack is undefined or empty and returns an empty string.

extractStack(error)

Returns the actual stack part of the error stack.

extractStack.lines(error)

Returns the stack lines of the error stack without the noise as a string[].

error

Type: Error | string | undefined

Either an Error or the .stack of an Error.

Related

extract-stack's People

Contributors

bendingbender avatar richienb avatar sindresorhus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

extract-stack's Issues

Firefox stack trace

Does this package handle the Firefox stack?

Chrome:

Error
    at fx (http://localhost:1234/test.e31bb0bc.js:3290:11)
    at HTMLDivElement.<anonymous> (http://localhost:1234/test.e31bb0bc.js:4219:19)
    at callAspect (http://localhost:1234/test.e31bb0bc.js:1088:35)
    at update (http://localhost:1234/test.e31bb0bc.js:1022:3)
    at spect (http://localhost:1234/test.e31bb0bc.js:998:3)
    at Test.fn (http://localhost:1234/test.e31bb0bc.js:4218:16)
    at Test.run (http://localhost:1234/test.e31bb0bc.js:500:14)
    at dequeue (http://localhost:1234/test.e31bb0bc.js:625:18)
    at dequeue (http://localhost:1234/test.e31bb0bc.js:608:14)
    at dequeue (http://localhost:1234/test.e31bb0bc.js:608:14)

Firefox:

fx@http://localhost:1234/test.e31bb0bc.js:3290:11
parcelRequire<["fx.js"]</</<@http://localhost:1234/test.e31bb0bc.js:4219:19
callAspect@http://localhost:1234/test.e31bb0bc.js:1088:35
update@http://localhost:1234/test.e31bb0bc.js:1022:3
spect@http://localhost:1234/test.e31bb0bc.js:998:3
parcelRequire<["fx.js"]</<@http://localhost:1234/test.e31bb0bc.js:4218:16
run@http://localhost:1234/test.e31bb0bc.js:500:14
dequeue@http://localhost:1234/test.e31bb0bc.js:625:18

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.