Big news!Introducing Socket AI - ChatGPT-Powered Threat Analysis. Learn more
Socket
Log inDemoInstall

clarify-error

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Issues
File Explorer

Advanced tools

clarify-error

Add some additional context to a JavaScript error

    1.0.0latest
    GitHub

Version published
Maintainers
1
Weekly downloads
237
decreased by-63.14%

Weekly downloads

Readme

Source

clarify-error

Wrap errors in explanations.

This is a spiritual successor to explain-error, rewritten after 8 years, using TypeScript, fixing some quirks and achieving 100% test coverage.

In Node.js sometimes something fails because of some internal detail, but then this error may be passed back somewhere else, too often, context is lost.

Example

const fs = require('fs') const explain = require('explain-error') // stat a file that does not exist. this will error, so add an explanation. function explainedError(cb) { fs.stat('neoatuhrcoahkrcophkr', (err) => { if (err) cb(explain(err, 'asked for a file that certainly did not exist')) else cb() }) } // this works even with multiple layers of explanations. explainedError(function (err) { throw explain(err, 'called an function that was expected to fail') })

Output:

fs.stat does not show where it was called from, but at least now you know what happened after that.

Error: called an function that was expected to fail at /home/staltz/oss/wrap-error/example.js:11:9 at /home/staltz/oss/wrap-error/example.js:5:14 Error: asked for a file that certainly did not exist at /home/staltz/oss/wrap-error/example.js:5:17 at FSReqCallback.oncomplete (fs.js:168:21) Error: ENOENT: no such file or directory, stat 'neoatuhrcoahkrcophkr'

License

MIT

FAQs

Last updated on 01 Mar 2022

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket
support@socket.devSocket SOC 2 Logo

Product

  • Package Issues
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc