setup-kubectl/node_modules/makeerror
github-actions[bot] 7ad2aa66bb
Add node modules and new code for release (#39)
Co-authored-by: tbarnes94 <tbarnes94@users.noreply.github.com>
2022-01-05 11:26:06 -05:00
..
lib Add node modules and new code for release (#39) 2022-01-05 11:26:06 -05:00
.travis.yml Add node modules and new code for release (#39) 2022-01-05 11:26:06 -05:00
license Add node modules and new code for release (#39) 2022-01-05 11:26:06 -05:00
package.json Add node modules and new code for release (#39) 2022-01-05 11:26:06 -05:00
readme.md Add node modules and new code for release (#39) 2022-01-05 11:26:06 -05:00

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