# human-error

> Errors that people can understand

Latest version **0.3.0** (published 2017-07-24) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2017-07-24 |
| First published | 2017-01-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Francisco Presencia |
| Maintainers | franciscop |
| Keywords | error, generate, pretty, print, show, mistake |

## Links

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

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 0.3.0 (latest) — 2017-07-24
- 0.2.0 — 2017-01-28
- 0.1.0 — 2017-01-27

## README

# human-error [![CircleCI](https://circleci.com/gh/franciscop/human-error.svg?style=shield)](https://circleci.com/gh/franciscop/human-error)

Allows you to write errors so people can understand:

| [![Show an error in the code](img/meta-run.png)](img/meta-run.png)  | [![Show an error in the code](img/meta-jest.png)](img/meta-jest.png)
|:---:|:---:|
| An error while running `node app.js` | Same error while testing with `jest` |



## Getting started

Install it with NPM:

```bash
npm install human-error
```

Then create your error codes:

```js
// myfun-errors.js
const errors = require('human-error')({
  // [optional] a url where the error is explained in-depth
  url: name => `http://example.com/error/${name}`
});

// "NAMESPACE" can be whatever you want (or nothing at all)
errors['NAMESPACE.missingcallback'] = () => `
  myFun() expects a callback to be passed but nothing was passed.
`;

errors['NAMESPACE.invalidcallback'] = ({ type }) => `
  myFun() expects the argument to be a callback function.
  ${type ? `"${type}" was passed instead.` : ''}
`;

module.exports = errors;
```

Then use them in your code:

```js
// myfun.js
const errors = require('./myfun-errors');

module.exports = (cb) => {
  if (!cb) {
    throw errors('NAMESPACE.missingcallback');
  }
  if (!(cb instanceof Function)) {
    throw errors('NAMESPACE.invalidcallback', { type: typeof cb });
  }
  cb('Cool library!');
};
```


## Options

- `url` [false]: if there's an url to show more info. It can be a string in which case it will just be printed or a function that build the error such as `(key) => 'https://example.com/errors#' + key` so you can show the appropriate support url.
- `extra` [{}]: an object that defaults to all of the options in the namespace. Useful for example for status code errors (`status: 500`) etc.
- `width` [80]: the minimum width of the row. It cannot cut strings since links shouldn't be cut.
- `plain` [false]: avoid generating a table and using plain-text only, in case some things break.

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