What is clean-stack?
The clean-stack npm package is designed to clean up error stack traces. It removes the noise from stack traces, making them easier to read and understand. This is particularly useful in development and production environments where error logs can become cluttered with irrelevant paths and lines. By simplifying stack traces, developers can more quickly identify the source of errors.
What are clean-stack's main functionalities?
Cleaning stack traces
This feature allows you to clean up the stack trace of an error. The `cleanStack` function takes an error stack as input and returns a cleaner, more readable version of it. This is particularly useful for logging and error handling in applications.
const cleanStack = require('clean-stack');
const error = new Error('An error occurred!');
console.log(cleanStack(error.stack));
Other packages similar to clean-stack
stack-trace
The 'stack-trace' package provides utilities for working with stack traces. It allows you to parse and inspect stack traces. Compared to 'clean-stack', 'stack-trace' offers more detailed manipulation and inspection capabilities but does not focus specifically on cleaning or simplifying the stack traces.
error-stack-parser
This package is used to parse JavaScript Error stack strings and extract stack frames from them. While 'error-stack-parser' focuses on parsing and extracting information from stack traces, 'clean-stack' is more about cleaning and simplifying them for better readability.
clean-stack
Clean up error stack traces
Removes the mostly unhelpful internal Node.js entries.
Also works in Electron.
Install
$ npm install clean-stack
Usage
import cleanStack from 'clean-stack';
const error = new Error('Missing unicorn');
console.log(error.stack);
console.log(cleanStack(error.stack));
API
cleanStack(stack, options?)
Returns the cleaned stack or undefined
if the given stack
is undefined
.
stack
Type: string | undefined
The stack
property of an Error
.
options
Type: object
pretty
Type: boolean
Default: false
Prettify the file paths in the stack:
/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15
→ ~/dev/clean-stack/unicorn.js:2:15
basePath
Type: string?
Remove the given base path from stack trace file paths, effectively turning absolute paths into relative ones.
Example with '/Users/sindresorhus/dev/clean-stack/'
as basePath
:
/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15
→ unicorn.js:2:15
Related