makeerror (1.0.12)

Published 2026-02-24 14:01:09 +00:00 by atheaadmin

Installation

registry=
npm install makeerror@1.0.12
"makeerror": "1.0.12"

About this package

makeerror Build Status

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:

function(message, data)

You'll typically do something like:

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:

er instanceof UnknownFileTypeError
er instanceof Error

Templatized Error Messages

There is support for simple string substitutions like:

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:

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:

er instanceof ChildError
er instanceof ParentError
er instanceof Error

Dependencies

Dependencies

ID Version
tmpl 1.0.5

Development Dependencies

ID Version
mocha 9.1.3
Details
npm
2026-02-24 14:01:09 +00:00
0
Naitik Shah
BSD-3-Clause
latest
2.5 KiB
Assets (1)
Versions (1) View all
1.0.12 2026-02-24