All Projects → ahmadnassri → Node Pretty Exceptions

ahmadnassri / Node Pretty Exceptions

Licence: isc
Pretty and more helpful uncaught exceptions, automatically

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Node Pretty Exceptions

dotty dict
Dictionary wrapper for quick access to deeply nested keys.
Stars: ✭ 67 (+204.55%)
Mutual labels:  lib
node-glob-promise
Promise version of glob
Stars: ✭ 43 (+95.45%)
Mutual labels:  lib
Expynent
A library that provides regular expression patterns. If you hate to write regular expressions, then expynent can help you.
Stars: ✭ 350 (+1490.91%)
Mutual labels:  lib
nimffmpeg
Nim FFMpeg binding
Stars: ✭ 29 (+31.82%)
Mutual labels:  lib
telegram-bot-api
This is an api-project for the telegram bot (HTTPS) api.
Stars: ✭ 16 (-27.27%)
Mutual labels:  lib
InstagramCpp
Instagram REST API client wirtten in C++
Stars: ✭ 24 (+9.09%)
Mutual labels:  lib
client-js
JS client for polygon.io api
Stars: ✭ 81 (+268.18%)
Mutual labels:  lib
Android Hot Libraries
收集总结 Android 项目中值得推荐的优秀开源项目
Stars: ✭ 755 (+3331.82%)
Mutual labels:  lib
faker
Faker is a Nim package that generates fake data for you.
Stars: ✭ 28 (+27.27%)
Mutual labels:  lib
Imageflow
High-performance image manipulation for web servers. Includes imageflow_server, imageflow_tool, and libimageflow
Stars: ✭ 3,643 (+16459.09%)
Mutual labels:  lib
dtkcore
Deepin Toolkit, core module
Stars: ✭ 45 (+104.55%)
Mutual labels:  lib
CockyGrabber
C# library for the collection of browser information such as cookies, logins, and more
Stars: ✭ 46 (+109.09%)
Mutual labels:  lib
Anet
A .NET Core Common Library , Framework and Boilerplate.
Stars: ✭ 255 (+1059.09%)
Mutual labels:  lib
nimjson
nimjson generates nim object definitions from json documents.
Stars: ✭ 37 (+68.18%)
Mutual labels:  lib
Nintendo Switch Eshop
Crawler for Nintendo Switch eShop
Stars: ✭ 463 (+2004.55%)
Mutual labels:  lib
Assembly-Lib
A 16-bits x86 DOS Assembly library that provides many useful functions for developing programs. It has both VGA grapics functions as well as general purpose utilities. The main purpose of this library was to be able to implement simple DOS games (in Assembly) using VGA (320x200, 256 colors) display.
Stars: ✭ 36 (+63.64%)
Mutual labels:  lib
python
A python package for sending logs to LogDNA
Stars: ✭ 36 (+63.64%)
Mutual labels:  lib
M3u8
Parser and generator of M3U8-playlists for Apple HLS. Library for Go language. 🎦
Stars: ✭ 800 (+3536.36%)
Mutual labels:  lib
Bounty
Javascript and SVG odometer effect library with motion blur
Stars: ✭ 724 (+3190.91%)
Mutual labels:  lib
Libmqtt
MQTT v3.1.1/5.0 library in Go
Stars: ✭ 290 (+1218.18%)
Mutual labels:  lib

Pretty Exceptions

Pretty and more helpful uncaught exceptions, automatically.

license release super linter test semantic

Usage

Library

const pretty = require('pretty-exceptions/lib')

const options = {
  source: true,
  native: true,
  color: true,
  cwd: process.cwd()
}

const output = pretty(new Error('foo'), options)

options

name type required default description
source Boolean false Show source code in stack
native Boolean false Show native code in stack
color Boolean true use ansi colors
cwd String process.cwd() resolve file names relative to this path

CLI (preferred)

This is the preferred approach to best avoid mistakingly including into production builds

  1. setup your NODE_PATH environment variable

    export NODE_PATH="$NODE_PATH:$(npm root -g)"
    
  2. install pretty-exceptions

    npm install --global pretty-exceptions
    
  3. run your application with the --require flag:

    node --require pretty-exceptions my-app.js
    
    # alternative modes (see below):
    node --require pretty-exceptions/source my-app.js
    

Pro Tip:

Use Bash Aliases for less typing

# make a special alias for debugging
alias node-ex='node --require pretty-exceptions'

# or even better:
alias node='node --require pretty-exceptions/source'

To make this persistent, you need to add this into your ~/.bashrc (or ~/.bash_profile).

Environment Variables

env default description
PRETTY_EXCEPTIONS_SOURCE 0 Show source code in stack
PRETTY_EXCEPTIONS_NATIVE 0 Show native code in stack
PRETTY_EXCEPTIONS_COLOR 1 use ansi colors

Source (if you really must!)

Require at the top-most entry point of your app:

require('pretty-exceptions')

// alternative modes (see below):
require('pretty-exceptions/source-native')

Modes

Default

$ node --require pretty-exceptions my-app.js
Output
Error: oh no! this is an error message!
 │
 └┬╼ /path/to/my-app.js
  │
  ├──╼ someOtherFunction @ line 2:27
  ├──╼ someFunction @ line 6:3
  └──╼ Object.<anonymous> @ line 9:1
Demo

Colors will vary based on your local terminal configuration

View Source

$ node --require pretty-exceptions/source my-app.js
# OR
$ PRETTY_EXCEPTIONS_SOURCE=1 node --require pretty-exceptions my-app.js
Output
Error: oh no! this is an error message!
 │
 └┬╼ /path/to/my-app.js
  │
  ├──╼ someOtherFunction @ line 2
  │
  │    function someOtherFunction () {
  ├╌╌╌╌╌╌╌╌╌╌╮
  │    throw new Error('oh no! this is an error message!')
  │    }
  │
  ├──╼ someFunction @ line 6
  │
  │    function someFunction () {
  ├╌╌╌╌╮
  │    someOtherFunction()
  │    }
  │
  ├──╼ Object.<anonymous> @ line 9
  │
  └╌╌╌╌╮
       someFunction()
Demo

Colors will vary based on your local terminal configuration

View Native Calls

$ node --require pretty-exceptions/native my-app.js
# OR
$ PRETTY_EXCEPTIONS_NATIVE=true node --require pretty-exceptions my-app.js
Output
Error: oh no! this is an error message!
 │
 ├─┬╼ /path/to/my-app.js
 │ │
 │ ├──╼ someOtherFunction @ line 2:27
 │ ├──╼ someFunction @ line 6:3
 │ └──╼ Object.<anonymous> @ line 9:1
 │
 ├─┬╼ module.js
 │ │
 │ ├──╼ Module._compile @ line 571:32
 │ ├──╼ Object.Module._extensions..js @ line 580:10
 │ ├──╼ Module.load @ line 488:32
 │ ├──╼ tryModuleLoad @ line 447:12
 │ ├──╼ Function.Module._load @ line 439:3
 │ └──╼ Module.runMain @ line 605:10
 │
 └┬╼ bootstrap_node.js
  │
  └──╼ run @ line 423:7
Demo

Colors will vary based on your local terminal configuration

View Source & Native

$ node --require pretty-exceptions/source-native my-app.js
# OR
$ PRETTY_EXCEPTIONS_SOURCE=1 PRETTY_EXCEPTIONS_NATIVE=1 node --require pretty-exceptions my-app.js
Output
Error: oh no! this is an error message!
 │
 ├─┬╼ /path/to/my-app.js
 │ │
 │ ├──╼ someOtherFunction @ line 2
 │ │
 │ │    function someOtherFunction () {
 │ ├╌╌╌╌╌╌╌╌╌╌╮
 │ │    throw new Error('oh no! this is an error message!')
 │ │    }
 │ │
 │ ├──╼ someFunction @ line 6
 │ │
 │ │    function someFunction () {
 │ ├╌╌╌╌╮
 │ │    someOtherFunction()
 │ │    }
 │ │
 │ ├──╼ Object.<anonymous> @ line 9
 │ │
 │ └╌╌╌╌╮
 │      someFunction()
 │ 
 │
 ├─┬╼ module.js
 │ │
 │ ├──╼ Module._compile @ line 571
 │ ├──╼ Object.Module._extensions..js @ line 580
 │ ├──╼ Module.load @ line 488
 │ ├──╼ tryModuleLoad @ line 447
 │ ├──╼ Function.Module._load @ line 439
 │ └──╼ Module.runMain @ line 605
 │
 └┬╼ bootstrap_node.js
  │
  └──╼ run @ line 423
Demo

Colors will vary based on your local terminal configuration


Author: Ahmad Nassri • Twitter: @AhmadNassri

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].