Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/shinnn/neat-stack

Make a color-coded stack trace from an error
https://github.com/shinnn/neat-stack

beautify colored error errors javascript log nodejs readability stacktrace terminal

Last synced: 26 days ago
JSON representation

Make a color-coded stack trace from an error

Awesome Lists containing this project

README

        

# neat-stack

[![npm version](https://img.shields.io/npm/v/neat-stack.svg)](https://www.npmjs.com/package/neat-stack)
[![Build Status](https://travis-ci.com/shinnn/neat-stack.svg?branch=master)](https://travis-ci.com/shinnn/neat-stack)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/neat-stack.svg)](https://coveralls.io/github/shinnn/neat-stack?branch=master)

Make a color-coded stack trace from an error

```javascript
const neatStack = require('neat-stack');
const request = require('request');

request('foo', err => console.error(neatStack(err)));
```

example

Useful for CLI applications — stack traces are not very important for end users but needed for authors to receive meaningful bug reports.

## Installation

[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/about-npm/).

```
npm install neat-stack
```

## API

```javascript
const neatStack = require('neat-stack');
```

### neatStack(*error*)

*error*: `Error`
Return: `string`

It returns a refined [`Error#stack`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error/Stack):

* Red-colored by [ANSI escape code](https://en.wikipedia.org/wiki/ANSI_escape_code).
* Lines starting with `' at'` are dimmed.
* [Any lines from Node.js internals are omitted](https://github.com/sindresorhus/clean-stack).
* Paths are simplified by [replacing a home directory with `~`](https://github.com/shinnn/tilde-path) on POSIX.

```javascript
const error = new Error('Hi');

error.stack; /* => `Error: Hi
at Object. (/Users/example/run.js:1:75)
at Module._compile (internal/modules/cjs/loader.js:654:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
at Module.load (internal/modules/cjs/loader.js:566:32)
at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
at Function.Module._load (internal/modules/cjs/loader.js:498:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:695:10)
at startup (internal/bootstrap/node.js:201:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)` */

neatStack(error); /* => `\u001b[31mError: Hi\u001b[2m
at Object. (~/example/run.js:1:88)\u001b[22m\u001b[39m` */
```

## License

[ISC License](./LICENSE) © 2017 - 2019 Shinnosuke Watanabe