makeerror

WebJar for makeerror

License

License

BSD 3-Clause
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

makeerror
Last Version

Last Version

1.0.11
Release Date

Release Date

Type

Type

jar
Description

Description

makeerror
WebJar for makeerror
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/daaku/nodejs-makeerror

Download makeerror

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/makeerror/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>makeerror</artifactId>
    <version>1.0.11</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/makeerror/
implementation 'org.webjars.npm:makeerror:1.0.11'
// https://jarcasting.com/artifacts/org.webjars.npm/makeerror/
implementation ("org.webjars.npm:makeerror:1.0.11")
'org.webjars.npm:makeerror:jar:1.0.11'
<dependency org="org.webjars.npm" name="makeerror" rev="1.0.11">
  <artifact name="makeerror" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='makeerror', version='1.0.11')
)
libraryDependencies += "org.webjars.npm" % "makeerror" % "1.0.11"
[org.webjars.npm/makeerror "1.0.11"]

Dependencies

compile (1)

Group / Artifact Type Version
org.webjars.npm : tmpl jar [1.0,1.1)

Project Modules

There are no modules declared in this project.

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

Versions

Version
1.0.11