Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xotic750/error-x
Create custom Javascript Error objects.
https://github.com/xotic750/error-x
browser ecmascript error nodejs
Last synced: 2 months ago
JSON representation
Create custom Javascript Error objects.
- Host: GitHub
- URL: https://github.com/xotic750/error-x
- Owner: Xotic750
- License: mit
- Created: 2015-11-21T17:55:10.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T23:03:35.000Z (about 2 years ago)
- Last Synced: 2024-11-09T21:51:33.603Z (2 months ago)
- Topics: browser, ecmascript, error, nodejs
- Language: JavaScript
- Size: 6.95 MB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 21
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## error-x
Create custom Javascript Error objects.
- [error-x](#module_error-x)
- [`module.exports`](#exp_module_error-x--module.exports) ⏏
- [.AssertionErrorConstructor](#module_error-x--module.exports.AssertionErrorConstructor) ⇐Error
- [`new AssertionErrorConstructor([message])`](#new_module_error-x--module.exports.AssertionErrorConstructor_new)
- [.ErrorConstructor](#module_error-x--module.exports.ErrorConstructor) ⇐Error
- [`new ErrorConstructor([message])`](#new_module_error-x--module.exports.ErrorConstructor_new)
- [.EvalErrorConstructor](#module_error-x--module.exports.EvalErrorConstructor) ⇐EvalError
- [`new EvalErrorConstructor([message])`](#new_module_error-x--module.exports.EvalErrorConstructor_new)
- [.InternalErrorConstructor](#module_error-x--module.exports.InternalErrorConstructor) ⇐Error
- [`new InternalErrorConstructor([message])`](#new_module_error-x--module.exports.InternalErrorConstructor_new)
- [.RangeErrorConstructor](#module_error-x--module.exports.RangeErrorConstructor) ⇐RangeError
- [`new RangeErrorConstructor()`](#new_module_error-x--module.exports.RangeErrorConstructor_new)
- [.ReferenceErrorConstructor](#module_error-x--module.exports.ReferenceErrorConstructor) ⇐ReferenceError
- [`new ReferenceErrorConstructor([message])`](#new_module_error-x--module.exports.ReferenceErrorConstructor_new)
- [.SyntaxErrorConstructor](#module_error-x--module.exports.SyntaxErrorConstructor) ⇐SyntaError
- [`new SyntaxErrorConstructor([message])`](#new_module_error-x--module.exports.SyntaxErrorConstructor_new)
- [.TypeErrorConstructor](#module_error-x--module.exports.TypeErrorConstructor) ⇐TypeError
- [`new TypeErrorConstructor([message])`](#new_module_error-x--module.exports.TypeErrorConstructor_new)
- [.URIErrorConstructor](#module_error-x--module.exports.URIErrorConstructor) ⇐URIError
- [`new URIErrorConstructor([message])`](#new_module_error-x--module.exports.URIErrorConstructor_new)
- [`.supportsAllConstructors`](#module_error-x--module.exports.supportsAllConstructors) :boolean
- [`.create([name], [ECTR])`](#module_error-x--module.exports.create) ⇒function
- [`.isErrorConstructor(value)`](#module_error-x--module.exports.isErrorConstructor) ⇒boolean
### `module.exports` ⏏
Want to create your own Error objects, this module will allow you to do
just that. It ships with all the standard ErrorConstructor objects already created
for you. Why? Well, these offer some improvements over the native versions.- They have a `toJSON` method and so they can be serialised.
- They have a standardised `stack` property, using
[`error-stack-parser`](https://github.com/stacktracejs/error-stack-parser)
messages and stacks are parsed and then re-formatted.
- They have a `frames` property which is an array of the parsed `stack`
message, so you have easy access to the information.#### module.exports.AssertionErrorConstructor ⇐
Error
**Kind**: static class of [
module.exports
](#exp_module_error-x--module.exports)
**Extends**:Error
##### `new AssertionErrorConstructor_new([message])`
Error constructor for test and validation frameworks that implement the
standardized AssertionError specification.| Param | Type | Description |
| --------- | ------------------- | -------------------------------- |
| [message] |Object
| Need to document the properties. |#### module.exports.ErrorConstructor ⇐
Error
**Kind**: static class of [
module.exports
](#exp_module_error-x--module.exports)
**Extends**:Error
##### `new ErrorConstructor([message])`
The Error constructor creates an error object.
| Param | Type | Description |
| --------- | ------------------- | ---------------------------------------- |
| [message] |string
| Human-readable description of the error. |#### module.exports.EvalErrorConstructor ⇐
EvalError
**Kind**: static class of [
module.exports
](#exp_module_error-x--module.exports)
**Extends**:EvalError
##### `new EvalErrorConstructor_new([message])`
Creates an instance representing an error that occurs regarding the
global function eval().| Param | Type | Description |
| --------- | ------------------- | ---------------------------------------- |
| [message] |string
| Human-readable description of the error. |#### module.exports.InternalErrorConstructor ⇐
Error
**Kind**: static class of [
module.exports
](#exp_module_error-x--module.exports)
**Extends**:Error
##### `new InternalErrorConstructor_new([message])`
The InternalError object indicates an error that occurred internally in
the JavaScript engine. For example: "InternalErrorConstructor: too much recursion".| Param | Type | Description |
| --------- | ------------------- | ---------------------------------------- |
| [message] |string
| Human-readable description of the error. |#### module.exports.RangeErrorConstructor ⇐
RangeError
**Kind**: static class of [
module.exports
](#exp_module_error-x--module.exports)
**Extends**:RangeError
##### `new RangeErrorConstructor_new()`
Creates an instance representing an error that occurs when a numeric
variable or parameter is outside of its valid range.| Type | Description |
| ------------------- | -------------------------------------------------- |
|string
| [message] Human-readable description of the error. |#### module.exports.ReferenceErrorConstructor ⇐
ReferenceError
**Kind**: static class of [
module.exports
](#exp_module_error-x--module.exports)
**Extends**:ReferenceError
##### `new ReferenceErrorConstructor_new([message])`
Creates an instance representing an error that occurs when de-referencing
an invalid reference| Param | Type | Description |
| --------- | ------------------- | ---------------------------------------- |
| [message] |string
| Human-readable description of the error. |#### module.exports.SyntaxErrorConstructor ⇐
SyntaError
**Kind**: static class of [
module.exports
](#exp_module_error-x--module.exports)
**Extends**:SyntaError
##### `new SyntaxErrorConstructor([message])`
Creates an instance representing a syntax error that occurs while parsing
code in eval().| Param | Type | Description |
| --------- | ------------------- | ---------------------------------------- |
| [message] |string
| Human-readable description of the error. |#### module.exports.TypeErrorConstructor ⇐
TypeError
**Kind**: static class of [
module.exports
](#exp_module_error-x--module.exports)
**Extends**:TypeError
##### `new TypeErrorConstructor([message])`
Creates an instance representing an error that occurs when a variable or
parameter is not of a valid type.| Param | Type | Description |
| --------- | ------------------- | ---------------------------------------- |
| [message] |string
| Human-readable description of the error. |#### module.exports.URIErrorConstructor ⇐
URIError
**Kind**: static class of [
module.exports
](#exp_module_error-x--module.exports)
**Extends**:URIError
##### `new URIErrorConstructor([message])`
Creates an instance representing an error that occurs when encodeURI() or
decodeURI() are passed invalid parameters.| Param | Type | Description |
| --------- | ------------------- | ---------------------------------------- |
| [message] |string
| Human-readable description of the error. |#### `module.exports.supportsAllConstructors` :
boolean
Indicates if the Javascript engine supports subclassing of all Error
types. If `true` then all are supported, if `false` (only very old
browsers IE6) then only `Error` is supported.**Kind**: static property of [
module.exports
](#exp_module_error-x--module.exports)#### `module.exports.create([name], [ECTR])` ⇒
function
Creates a custom Error constructor. Will use `ErrorConstructor` if argument is not
a valid constructor.**Kind**: static method of [
module.exports
](#exp_module_error-x--module.exports)
**Returns**:function
- The custom Error constructor.| Param | Type | Default | Description |
| ------ | --------------------- | ------------------------------------------ | ------------------------------ |
| [name] |string
|"'Error'"
| The name for the custom Error. |
| [ECTR] |function
|Error
| Error constructor to be used. |**Example**
```js
import * as errorX from 'error-x';const MyError = errorX.create('MyError'); // Uses `Error` as no constructor
// specified.
const err = new MyError('somethingHappened');JSON.stringify(err); // => see below.
// A serialised error, showing the custom error object's structure and
// format
// {
// "name": "MyError",
// "message": "somethingHappened",
// "frames": [
// {
// "functionName": "Y.x",
// "fileName": "http://fiddle.jshell.net/2k5x5dj8/183/show/",
// "lineNumber": 65,
// "columnNumber": 13,
// "source": "Y.x (http://fiddle.jshell.net/2k5x5dj8/183/show/:65:13)"
// },
// {
// "functionName": "window.onload",
// "fileName": "http://fiddle.jshell.net/2k5x5dj8/183/show/",
// "lineNumber": 73,
// "columnNumber": 3,
// "source": "window.onload (http://fiddle.jshell.net/2k5x5dj8/183/show/:73:3)"
// }
// ],
// "stack": "MyError\n Y.x()@http://fiddle.jshell.net/2k5x5dj8/183/show/:65:13\n window.onload()@http://fiddle.jshell.net/2k5x5dj8/183/show/:73:3"
// }
```#### `module.exports.isErrorConstructor(value)` ⇒
boolean
Determine whether or not a given `value` is an `Error` type.
**Kind**: static method of [
module.exports
](#exp_module_error-x--module.exports)
**Returns**:boolean
- Returns `true` if `value` is an `Error` type,
else `false`.| Param | Type | Description |
| ----- | --------------- | ------------------------ |
| value |\*
| The object to be tested. |