@specialblend/pretty-error

0.0.8 • Public • Published

pretty-error

Readable, property-bearing custom ES6 errors for Node.js

install

npm install @specialblend/pretty-error

Example

import PrettyError from '@specialblend/pretty-error';

class JSONError extends PrettyError {}

export const parseJSON = str => {
  try {
    return JSON.parse(str);
  } catch (err) {
    throw new JSONError('Invalid JSON!', { str })
  }
}

Output:

JSONError: Invalid JSON!
{
  str: '{this;is-not.valid/json'
}
    at parseJSON (/Users/specialblend/workspace/pretty-error/examples/parse-json.js:11:15)
    at Object.parseJSON (/Users/specialblend/workspace/pretty-error/examples/parse-json.js:15:1)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Module._compile (/Users/specialblend/workspace/pretty-error/node_modules/pirates/lib/index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Object.newLoader [as .js] (/Users/specialblend/workspace/pretty-error/node_modules/pirates/lib/index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)

Readme

Keywords

Package Sidebar

Install

npm i @specialblend/pretty-error

Weekly Downloads

0

Version

0.0.8

License

ISC

Unpacked Size

9.06 kB

Total Files

5

Last publish

Collaborators

  • __specialblend__