Skip to content

Latest commit

 

History

History
46 lines (31 loc) · 945 Bytes

File metadata and controls

46 lines (31 loc) · 945 Bytes

pretty-error-tree

Pretty-prints Node.js Error objects in a tree style.

  • Shows lines of source code
  • Flattens nested causes
  • Shortens file paths
  • Highlights function names
  • Colors the output
  • Filters out internal Node.js frames

pretty-error-tree output

Here's the default Node.js error output for comparison:

Default node error output

Installation

yarn add pretty-error-tree@chrismwendt/pretty-error-tree

Usage

Pretty-print an error:

import { prettyErrorTree } from 'chrismwendt/pretty-error-tree'

try {
  throw new Error('foo')
} catch (err) {
  console.log(prettyErrorTree(err))
}

Install a global handler for uncaught errors:

import { installPrettyErrorTree } from 'chrismwendt/pretty-error-tree'

installPrettyErrorTree() // Now all uncaught errors will be pretty-printed

throw new Error('foo') // This will be pretty-printed