highlight-stack
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

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)
})

/highlight-stack/

    Package Sidebar

    Install

    npm i highlight-stack

    Weekly Downloads

    0

    Version

    0.3.0

    License

    MIT

    Unpacked Size

    178 kB

    Total Files

    14

    Last publish

    Collaborators

    • lohfu