# clarify-error

> Add some additional context to a JavaScript error

Latest version **1.0.0** (published 2022-03-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install clarify-error
pnpm add clarify-error
yarn add clarify-error
bun add clarify-error
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-03-01 |
| First published | 2022-03-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 5.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Andre Staltz |
| Maintainers | staltz |

## Links

- npm: https://www.npmjs.com/package/clarify-error
- Repository: https://github.com/staltz/clarify-error
- Homepage: https://github.com/staltz/clarify-error#readme
- Issues: https://github.com/staltz/clarify-error/issues
- npm.io page: https://npm.io/package/clarify-error

## Recent versions

- 1.0.0 (latest) — 2022-03-01
- 0.0.1 — 2022-03-01

## README

# clarify-error

Wrap errors in explanations.

> This is a spiritual successor to [explain-error](https://github.com/dominictarr/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

```js
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

---
_Source: https://npm.io/package/clarify-error · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
