Skip to content

10xEngineersQualityProgramming/immediate-error

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Immediate-error

This is a utility to throw an error.

const { immediateError, ErrorType } = require('immediate-error')

immediateError() // this will throw a regular Error with the default message of "ERROR!"

immediateError('Aaaaah') // this will throw a regular Error with the message "Aaaaah"

immediateError('Aaaaah', ErrorType.BaseError) // does the same thing as above

immediateError('Assertion error', ErrorType.AssertionError) // throws an AssertionError (from the assert-fn module)

immediateError('Assertion error', ErrorType.NativeAssertionError) // throws an AssertionError (from the node:assert module)

immediateError('Range error', ErrorType.RangeError) // throws a RangeError

immediateError('Reference error', ErrorType.ReferenceError) // throws a ReferenceError

immediateError('Syntax error', ErrorType.SyntaxError) // throws a SyntaxError

immediateError('type error', ErrorType.TypeError) // throws a TypeError

class MyCustomError extends Error {
  constructor (message) {
    super("Custom: " + message)
  }
}

immediateError('Error!', MyCustomError) // throws a MyCustomError with the message "Error!" which in turn prints out "Custom: Error!" because we used our own error class

Why?

This module is great because it uses the best practices in JavaScript such as using dependencies like throw-error and yanoop to throw errors and using es-errors instead of using the error classes natively.

Show your support

Follow me on GitHub and star my repositories.

is this a joke?

Of course not!























(Yes, it is.)

About

Alternative to throw new Error

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published