1.0.0 • Published 4 years ago

prettier_errors v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Prettier Errors

Example 1

Example 2

Example 3

Example 3

A tiny, lightweight, and experimental npm library which prettifies javascript errors and warnings! The module can work with:

  • All built-in runtime errors
  • Custom errors from other libraries
  • Promise rejections
  • Warnings

But, the library will not handle, and even make these worse:

  • If an object that's not an error is thrown (throw "")
  • If a promise is rejected and not caught with something that's not an error as the reason (reject(""))

Install

npm i prettier_errors

Usage

Setup the library

// At the top of your main file:
const settings = {
    proximity: 0, // How much lines to include in the error other than the main line
    stack_depth: 0, // How much of the stack to be shown in the error
    skip_empty_lines: false // Skip empty lines when showing the error, more compact but less readable, only matters when 'proximity' is more than 0.
};

// The first parameter tells the library which errors to prettify
// true - All errors
// false - Only errors which extend "PrettyError"s
require("prettyerrors").setup(true, settings);

Throw a pretty error

const {PrettyError} = require("prettyerrors");

// Usually you should extend this class
throw new PrettyError("This is a simple prettified error");
1.0.0

4 years ago