object
Errors : Custom and Explicit Javascript Error Classes
bower install browser-error-classes
Easy to read custom and extensible error classes for the browser which extend the native error classes.
Include all the errors with Error.js
OR include just what you need from the lib/
dir.
Sometimes, just throwing an error isn't that helpful. Sometimes, handling an error elegantly preventing a crash just isn't quite good enough sometimes you want to handle explicit errors in the UI in specific ways. During team development there are times when you want to throw explicit errors to both help developers understand whats going on, as well as enforce some strict rules. That is what this module is for.
Kind: global namespace
Example
<script src='bower_components/browser-error-classes/Errors.js'></script>
- Errors :
object
- .Immutable ⇐
Error
- .InvalidMethod ⇐
Error
- .InvalidParameter ⇐
Error
- .RequiredParameter ⇐
Error
- .SocketUnavailable ⇐
Error
- .Type ⇐
TypeError
- .UndefinedValue ⇐
Error
- .Immutable ⇐
Error
Errors.Immutable ⇐ Kind: static class of Errors
Extends: Error
- .Immutable ⇐
Error
new Immutable()
Error for Immutable variables
String
Immutable.setMessage(varaibleName, scope) ⇒ Kind: static method of Immutable
Returns: String
- compiled error message
Param | Type | Description |
---|---|---|
varaibleName | String |
name of immutable variable |
scope | Any |
Scope of varaible |
Example
{ Object; let userName=null; { return userName; } { ifuserName const err=; err; throw err; userName=value; return userName; } ifname thisname=name; } const bob='bob'42; bobname='bob';
Example
immutable.html:39 Uncaught Immutable: "name" is Immutable and may not be modified. Scope :
Error
Errors.InvalidMethod ⇐ Kind: static class of Errors
Extends: Error
- .InvalidMethod ⇐
Error
new InvalidMethod()
Error for methods which are either undefined or not methods (functions)
String
InvalidMethod.setMessage(methodName, method, [scope]) ⇒ Kind: static method of InvalidMethod
Returns: String
- compiled error message
Param | Type | Description |
---|---|---|
methodName | String |
method name |
method | Any |
expected method |
[scope] | Any |
scope in which the invalid method is expected |
Example
{ thisname=name; thisage=age; } const bob='bob'42; if!bobgetInfo || typeof bobgetInfo !== 'function' const err=; err;
Example
invalidMethod.html:25 Uncaught InvalidMethod: Expects "getInfo" to be Function but got undefined Scope :
Error
Errors.InvalidParameter ⇐ Kind: static class of Errors
Extends: Error
- .InvalidParameter ⇐
Error
new InvalidParameter()
Error for invalid parameters
String
InvalidParameter.setMessage(parameterName, expected, got, [scope]) ⇒ Kind: static method of InvalidParameter
Returns: String
- compiled error message
Param | Type | Description |
---|---|---|
parameterName | Any |
name of parameter |
expected | Any |
what it expected |
got | Any |
what it got |
[scope] | Any |
optional value where the parameter came from like an object or array |
Example
let test=a:1b:0; iftestb<1 err=; err; throw err;
Example
InvalidParameter: 'b' Expects 'a value greater than 0' but got 0 at InvalidParameter at multiplyNumbers
Error
Errors.RequiredParameter ⇐ Kind: static class of Errors
Extends: Error
- .RequiredParameter ⇐
Error
new RequiredParameter()
error for required params that are not set or passed
String
RequiredParameter.setMessage(parameterName, [scope]) ⇒ Kind: static method of RequiredParameter
Returns: String
- compiled error message
Param | Type | Description |
---|---|---|
parameterName | Any |
name of parameter |
[scope] | Any |
optional value where the parameter came from like an object or array |
Example
let test=a:1b:0; if!testc err=; err; throw err;
Example
RequiredParameter: Expects 'numberOne' to be defined at RequiredParameter at multiplyNumbers
Error
Errors.SocketUnavailable ⇐ Kind: static class of Errors
Extends: Error
- .SocketUnavailable ⇐
Error
new SocketUnavailable()
Error for when an expected socket is not available
String
SocketUnavailable.setMessage(socketPath, [scope]) ⇒ Kind: static method of SocketUnavailable
Returns: String
- compiled error message
Param | Type | Description |
---|---|---|
socketPath | Any |
name of parameter |
[scope] | Any |
optional value with information on the socket or constructor |
Example
const ipc=; const Errors=; ipcconfigid = 'hello'; ipcconfigmaxRetries = 3; ipcconfigsilent=true; ipc;
Example
SocketUnavailable: Socket of '/tmp/app.world' Unavailable at SocketUnavailable at Object.<anonymous> at Object.pub at Object.trigger at Socket.connectionClosed at emitOne at Socket.emit at Pipe._onclose
TypeError
Errors.Type ⇐ Kind: static class of Errors
Extends: TypeError
- .Type ⇐
TypeError
new Type()
Used for normalizing the message of a type error
String
Type.setMessage(parameterName, type, value, [scope]) ⇒ Kind: static method of Type
Returns: String
- compiled error message
Param | Type | Description |
---|---|---|
parameterName | Any |
name of parameter |
type | String |
Type String |
value | Any |
value that caused error |
[scope] | Any |
optional value where the parameter came from like an object or array |
Example
let test=a:1b:0; iftypeof testb!=='object' err=; err; throw err;
Example
git/node-error-classes/example/typeError.js:19 throw err; ^ TypeError: 'numberOne' Expects String but got number : 6 at Type at multiplyNumbers
Error
Errors.UndefinedValue ⇐ Kind: static class of Errors
Extends: Error
new UndefinedValue()
Error for undefined values
String
UndefinedValue.setMessage(variableName, variable, [scope]) ⇒ Kind: static method of UndefinedValue
Returns: String
- compiled error message
Param | Type | Description |
---|---|---|
variableName | String |
varible name |
variable | Any |
varible |
[scope] | Any |
scope in which the variable should exist |
Example
const user= name:'bob' if!userage const err = ; err; throw err;
Example
git/node-error-classes/example/undefinedValue.js:14 throw err; ^ Undefined: 'string'