https://github.com/10xengineersqualityprogramming/immediate-error
Alternative to throw new Error
https://github.com/10xengineersqualityprogramming/immediate-error
Last synced: 12 months ago
JSON representation
Alternative to throw new Error
- Host: GitHub
- URL: https://github.com/10xengineersqualityprogramming/immediate-error
- Owner: 10xEngineersQualityProgramming
- Created: 2024-08-23T18:31:26.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-06-09T17:12:00.000Z (about 1 year ago)
- Last Synced: 2025-06-09T18:24:55.386Z (about 1 year ago)
- Language: JavaScript
- Size: 56.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Immediate-error
This is a utility to throw an error.
```javascript
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('Aggregate error', ErrorType.AggregateError) // throws an AggregateError
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`](https://npmjs.com/package/throw-error) and [`yanoop`](https://npmjs.com/package/yanoop) to throw errors and using [`es-errors`](https://npmjs.com/package/es-errors) instead of using the error classes natively.
## Show your support
[Follow me on GitHub](https://github.com/tj-commits) and star my repositories.
## is this a joke?
Of course not!
(Yes, it is.)