Big update!Announcing Socket for GitHub 1.0. Learn more
Socket
BlogLoveFAQ
Install
Log in

makeerror

Package Overview
Dependencies
1
Maintainers
1
Versions
11
Issues
File Explorer

Advanced tools

makeerror

A library to make errors.

    1.0.12latest

Version published
Maintainers
1
Weekly downloads
17,203,234
increased by1.54%

Weekly downloads

Readme

Source

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

FAQs

What is makeerror?

A library to make errors.

Is makeerror popular?

The npm package makeerror receives a total of 16,448,607 weekly downloads. As such, makeerror popularity was classified as popular.

Is makeerror well maintained?

We found that makeerror demonstrated a healthy version release cadence and project activity. It has 1 open source maintainer collaborating on the project.

Last updated on 23 Oct 2021
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc