/highlight-stack

highlights the name of local (not in node_modules) files in error stack

Primary LanguageJavaScriptMIT LicenseMIT

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 highlight-stack

Usage

Builds both CJS and ESM versions.

import highlightStack from 'highlight-stack')
// or
const highlightStack = require('highlight-stack')

General

try {
  doDodgyStuff()
} catch (err) {
  console.error(highlightStack(err.stack))
}

To make uncaught exceptions unhandled rejections easier to read:

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

process.on('unhandledRejection', (err) => {
  console.error(chalk.red('UNHANDLED REJECTION'))

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

  process.exit(1)
})