makeerror
A library to make errors.
Last updated 3 years ago by daaku .
BSD-3-Clause · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install makeerror 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.0.12                                ...           latest (3 years ago)

11 Versions

  • 1.0.12                                ...           3 years ago
  • 1.0.11                                ...           10 years ago
  • 1.0.10                                ...           10 years ago
  • 1.0.8                                ...           13 years ago
  • 1.0.7                                ...           13 years ago
  • 1.0.6                                ...           13 years ago
  • 1.0.4                                ...           13 years ago
  • 1.0.3                                ...           13 years ago
  • 1.0.2                                ...           13 years ago
  • 1.0.1                                ...           13 years ago
  • 1.0.0                                ...           13 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (1)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |