0.3.0 • Published 3 years ago

highlight-stack v0.3.0

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

Highlight Stack

A module to make it easier for humans to read logged stack traces in node.

This module will remove the current working directory from all paths, highlight local file paths and node_modules' names and fade all lines referring to node internals.

Installation

$ npm install @bmp/highlight-stack

Usage

General

try {
  doDodgyStuff()
} catch (e) {
  console.error( `[${e.name}] ${e.message}`)

  if (error.stack) {
    console.error(highlightStack(e.stack.slice(e.stack.indexOf('\n') + 1)).trim())
  }
}

To make uncaught exceptions easier to read:

const hightlightStack = require('@bmp/highlight-stack')
process.on('uncaughtException', (err) => {
  console.error(chalk.red('UNCAUGHT EXCEPTION'))

  if (err.stack) {
    console.error(highlightStack(err.stack))
  } else {
    console.error(err)
  }

  process.exit(1)
})
0.3.0

3 years ago

0.2.1

5 years ago

0.2.0

5 years ago