What is error-stack-parser?
The error-stack-parser package is a utility for parsing and extracting information from JavaScript Error stacks. It provides a structured way to interpret error stack strings, making it easier to programmatically analyze errors, log them in a more readable format, or display them in user interfaces. It's particularly useful in applications where understanding the context and source of an error is crucial for debugging or error handling.
What are error-stack-parser's main functionalities?
Parsing Error Stacks
This feature allows you to parse the stack property of Error objects into a more structured format. Each element in the returned array represents a frame in the stack trace, with properties such as the function name, file name, line number, and column number. This makes it easier to analyze and display error information programmatically.
const ErrorStackParser = require('error-stack-parser');
const error = new Error('This is a test error');
const stackFrames = ErrorStackParser.parse(error);
console.log(stackFrames);
Other packages similar to error-stack-parser
stacktrace-js
stacktrace-js provides similar functionality to error-stack-parser by offering mechanisms to capture, parse, and manipulate JavaScript stack traces. It goes a bit further by also allowing stack trace collection from all browsers and generating stack traces from thrown errors or caught exceptions. Compared to error-stack-parser, stacktrace-js might offer a broader set of features for handling stack traces across different environments.
source-map-support
source-map-support is a package that adds source map support to node.js (for converting compiled code locations to their original source locations). While not a direct alternative to error-stack-parser, it complements its functionality by allowing developers to obtain accurate stack traces in their original source code, not the transpiled or compiled version. This is especially useful in projects where code is bundled or transpiled.
Simple, cross-browser Error parser.
This library parses and extracts function names, URLs, line numbers, and column numbers from the given Error's stack
as
an Array of StackFrames.
Once you have parsed out StackFrames, you can do much more interesting things. See stacktrace-gps.
Note that in IE9 and earlier, Error
objects don't have enough information to extract much of anything. In IE 10, Error
s
are given a stack
once they're throw
n.
Browser Support
Usage
ErrorStackParser.parse(new Error('boom'));
=> [
StackFrame('funky1', [], 'path/to/file.js', 35, 79),
StackFrame('filter', undefined, 'https://cdn.somewherefast.com/utils.min.js', 1, 832),
StackFrame(... and so on ...)
]
Installation
npm install error-stack-parser
bower install error-stack-parser
https://raw.githubusercontent.com/stacktracejs/error-stack-parser/master/dist/error-stack-parser.min.js
Contributing
Want to be listed as a Contributor? Start with the Contributing Guide!