Socket
Socket
Sign inDemoInstall

format-error

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

format-error

formats an error for display


Version published
Weekly downloads
1.8K
increased by52.32%
Maintainers
1
Weekly downloads
 
Created
Source

format-error

Formats an error object such that:

  • message is ignored; assumes it's in the stack
  • full stack is displayed
  • other properties on object are displayed
  • nested errors are displayed

install

npm install --save format-error

example

var format = require('format-error').format;

var error = new Error('something broke');
error.inner = new Error('some inner thing broke');
error.code = '500c';
error.severity = 'high';

var message = format(error);

console.error(message);

/*
Error:    something broke
    at Object.<anonymous> (/home/sean/demo/testium/err.js:28:13)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3
inner:
  Error: some inner thing broke
    at Object.<anonymous> (/home/sean/demo/testium/err.js:29:15)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3
code:     500c
severity: high
*/

api

format(error, prettyjsonOptions)

Formats an error for output. error is an Error object. prettyjsonOptions (optional) is passed directly to prettyjson.

patchError()

Permanently patches the error object such that serialization (toJSON calls) behave according to the goals of this module. This is not required unless you want JSON.stringify(error) to act somewhat like format(error) in cases where you can't control how the output is formatted directly.

This module only temporarily patches Error in order to produce the formatted output.

This can be undone by calling unpatchError().

unpatchError()

This reverts changes made to Error.prototype.toJSON by patchError().

This should only be called if you explictly called patchError.

License

MIT

FAQs

Package last updated on 20 Mar 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc