@hutechwebsite/voluptates-illum-cupiditate-quos

1.0.0 • Public • Published

@hutechwebsite/voluptates-illum-cupiditate-quos

A little function that formats an error object as a nice, readable string. Works in node and the browser; in node, it will use kleur to add ANSI color code escape sequences to the output string, to make it easier to read.

Features

  • Works in both node and the browser
  • Browser version is only ~2k
  • Error name and stack are printed in color
  • Handles non-error inputs gracefully (accepts unknown in TypeScript)
  • Also prints any additional properties that were added to the Error object
    • This is particularly nice when working with node's fs errors; node sometimes puts the information about eg "which file couldn't be read" is sometimes in a property on the error, rather than in the error message, so by printing additional properties, it's guaranteed to be visible.

Example

Sample output of using @hutechwebsite/voluptates-illum-cupiditate-quos in the node repl. See the "Usage" section below for the code used in this screenshot.

Installation

npm install @hutechwebsite/voluptates-illum-cupiditate-quos

Usage

import { formatError } from "@hutechwebsite/voluptates-illum-cupiditate-quos";

const error = new Error("uh oh!");

error.context = {
  user: "jeff",
  session: "ewnj75hvj3v4tvmuy43er",
  favoriteIceCreamFlavor: "pineapple",
};

console.log(formatError(error));
/*
  Logs:

  Error: uh oh!
    at REPL2:1:9
  The above error also had these properties on it:
  {
    context: {
      user: 'jeff',
      session: 'ewnj75hvj3v4tvmuy43er',
      favoriteIceCreamFlavor: 'pineapple'
    }
  }
*/

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i @hutechwebsite/voluptates-illum-cupiditate-quos

Weekly Downloads

10

Version

1.0.0

License

MIT

Unpacked Size

16.5 kB

Total Files

8

Last publish

Collaborators

  • khaipham1002