
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
clarify-error
Advanced tools
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.
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'
MIT
FAQs
Add some additional context to a JavaScript error
We found that clarify-error demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.