# zerr

> custom error construction

Latest version **1.0.4** (published 2016-01-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install zerr
pnpm add zerr
yarn add zerr
bun add zerr
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2016-01-27 |
| First published | 2015-09-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Paul Frazee |
| Maintainers | pfraze |
| Keywords | error |

## Links

- npm: https://www.npmjs.com/package/zerr
- Repository: https://github.com/pfraze/zerr
- Homepage: https://github.com/pfraze/zerr#readme
- Issues: https://github.com/pfraze/zerr/issues
- npm.io page: https://npm.io/package/zerr

## 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

- 1.0.4 (latest) — 2016-01-27
- 1.0.3 — 2015-09-21
- 1.0.2 — 2015-09-21
- 1.0.1 — 2015-09-15
- 1.0.0 — 2015-09-13

## README

# ZErr

Custom JS error creator that subclasses `Error`, sets `.name` `.stack` and `.message`, and provides simple interpolation to construct error messages.

```js
var zerr = require('zerr')

// first param: error name
// second param: string template for error messages (substitutes '%' with args in constructor)
var BadParam = zerr('BadParam', '% must be a %')

// using the created error:
try { throw new BadParam('foo', 'string') }
catch (e) {
  console.log(e.name) // => 'BadParamError'
  console.log(e.message) // => 'foo must be a string'
  console.log(e.stack) // => 'BadParamError: foo must be a string\nat repl:1:13...'
  console.log(e instanceof Error) // => true
  console.log(e instanceof BadParam) // => true
}

// the `new` is optional
throw BadParam('foo', 'string')

// if no string template is given, zerr will just use the constructor's param as the message
var BadParam = zerr('BadParam')
try { throw new BadParam('foo is bad') }
catch (e) {
  console.log(e.message) // => 'foo is bad'
}

// if you pass an error as the first param to the constructor, zerr will add its stack to the stack history
// (taken from https://github.com/dominictarr/explain-error)
try { throw new BadParam(new BadParam('earlier foo was bad'), 'foo is bad') }
catch (e) {
  console.log(e.stack) /* =>
  BadPararmError: foo is bad
      at repl:1:7
    BadPararmError: earlier foo was bad
      at repl:1:15
  */
}
```

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