# makeerror

> A library to make errors.

Latest version **1.0.12** (published 2021-10-23) · BSD-3-Clause license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.12 |
| Published | 2021-10-23 |
| First published | 2011-07-24 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | separate (@types/makeerror) |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Naitik Shah |
| Maintainers | daaku |

## Links

- npm: https://www.npmjs.com/package/makeerror
- Repository: https://github.com/daaku/nodejs-makeerror
- Homepage: https://github.com/daaku/nodejs-makeerror#readme
- Issues: https://github.com/daaku/nodejs-makeerror/issues
- npm.io page: https://npm.io/package/makeerror

## Dependencies (1)

- [tmpl](https://npm.io/package/tmpl.md) 1.0.5

## Recent versions

- 1.0.12 (latest) — 2021-10-23
- 1.0.11 — 2015-03-28
- 1.0.10 — 2015-03-04
- 1.0.8 — 2011-08-17
- 1.0.7 — 2011-08-17
- 1.0.6 — 2011-08-17
- 1.0.4 — 2011-08-17
- 1.0.3 — 2011-08-08
- 1.0.2 — 2011-08-08
- 1.0.1 — 2011-07-27
- 1.0.0 — 2011-07-24

## README

makeerror [![Build Status](https://secure.travis-ci.org/nshah/nodejs-makeerror.png)](http://travis-ci.org/nshah/nodejs-makeerror)
=========

A library to make errors.


Basics
------

Makes an Error constructor function with the signature below. All arguments are
optional, and if the first argument is not a `String`, it will be assumed to be
`data`:

```javascript
function(message, data)
```

You'll typically do something like:

```javascript
var makeError = require('makeerror')
var UnknownFileTypeError = makeError(
  'UnknownFileTypeError',
  'The specified type is not known.'
)
var er = UnknownFileTypeError()
```

`er` will have a prototype chain that ensures:

```javascript
er instanceof UnknownFileTypeError
er instanceof Error
```


Templatized Error Messages
--------------------------

There is support for simple string substitutions like:

```javascript
var makeError = require('makeerror')
var UnknownFileTypeError = makeError(
  'UnknownFileTypeError',
  'The specified type "{type}" is not known.'
)
var er = UnknownFileTypeError({ type: 'bmp' })
```

Now `er.message` or `er.toString()` will return `'The specified type "bmp" is
not known.'`.


Prototype Hierarchies
---------------------

You can create simple hierarchies as well using the `prototype` chain:

```javascript
var makeError = require('makeerror')
var ParentError = makeError('ParentError')
var ChildError = makeError(
  'ChildError',
  'The child error.',
  { proto: ParentError() }
)
var er = ChildError()
```

`er` will have a prototype chain that ensures:

```javascript
er instanceof ChildError
er instanceof ParentError
er instanceof Error
```

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