check-error

WebJar for check-error

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

check-error
Last Version

Last Version

1.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

check-error
WebJar for check-error
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/chaijs/check-error

Download check-error

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/check-error/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>check-error</artifactId>
    <version>1.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/check-error/
implementation 'org.webjars.npm:check-error:1.0.2'
// https://jarcasting.com/artifacts/org.webjars.npm/check-error/
implementation ("org.webjars.npm:check-error:1.0.2")
'org.webjars.npm:check-error:jar:1.0.2'
<dependency org="org.webjars.npm" name="check-error" rev="1.0.2">
  <artifact name="check-error" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='check-error', version='1.0.2')
)
libraryDependencies += "org.webjars.npm" % "check-error" % "1.0.2"
[org.webjars.npm/check-error "1.0.2"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

ChaiJS check-error

Error comparison and information related utility for node and the browser.

license:mit tag:? build:? coverage:? npm:? dependencies:? devDependencies:?
Selenium Test Status
Join the Slack chat Join the Gitter chat

What is Check-Error?

Check-Error is a module which you can use to retrieve an Error's information such as its message or constructor name and also to check whether two Errors are compatible based on their messages, constructors or even instances.

Installation

Node.js

check-error is available on npm. To install it, type:

$ npm install check-error

Browsers

You can also use it within the browser; install via npm and use the check-error.js file found within the download. For example:

<script src="./node_modules/check-error/check-error.js"></script>

Usage

The primary export of check-error is an object which has the following methods:

  • compatibleInstance(err, errorLike) - Checks if an error is compatible with another errorLike object. If errorLike is an error instance we do a strict comparison, otherwise we return false by default, because instances of objects can only be compatible if they're both error instances.
  • compatibleConstructor(err, errorLike) - Checks if an error's constructor is compatible with another errorLike object. If err has the same constructor as errorLike or if err is an instance of errorLike.
  • compatibleMessage(err, errMatcher) - Checks if an error message is compatible with an errMatcher RegExp or String (we check if the message contains the String).
  • getConstructorName(errorLike) - Retrieves the name of a constructor, an error's constructor or errorLike itself if it's not an error instance or constructor.
  • getMessage(err) - Retrieves the message of an error or err itself if it's a String. If err or err.message is undefined we return an empty String.
var checkError = require('check-error');

.compatibleInstance(err, errorLike)

var checkError = require('check-error');

var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
var caughtErr;

try {
  funcThatThrows();
} catch(e) {
  caughtErr = e;
}

var sameInstance = caughtErr;

checkError.compatibleInstance(caughtErr, sameInstance); // true
checkError.compatibleInstance(caughtErr, new TypeError('Another error')); // false

.compatibleConstructor(err, errorLike)

var checkError = require('check-error');

var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
var caughtErr;

try {
  funcThatThrows();
} catch(e) {
  caughtErr = e;
}

checkError.compatibleConstructor(caughtErr, Error); // true
checkError.compatibleConstructor(caughtErr, TypeError); // true
checkError.compatibleConstructor(caughtErr, RangeError); // false

.compatibleMessage(err, errMatcher)

var checkError = require('check-error');

var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
var caughtErr;

try {
  funcThatThrows();
} catch(e) {
  caughtErr = e;
}

var sameInstance = caughtErr;

checkError.compatibleMessage(caughtErr, /TypeError$/); // true
checkError.compatibleMessage(caughtErr, 'I am a'); // true
checkError.compatibleMessage(caughtErr, /unicorn/); // false
checkError.compatibleMessage(caughtErr, 'I do not exist'); // false

.getConstructorName(errorLike)

var checkError = require('check-error');

var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
var caughtErr;

try {
  funcThatThrows();
} catch(e) {
  caughtErr = e;
}

var sameInstance = caughtErr;

checkError.getConstructorName(caughtErr) // 'TypeError'

.getMessage(err)

var checkError = require('check-error');

var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
var caughtErr;

try {
  funcThatThrows();
} catch(e) {
  caughtErr = e;
}

var sameInstance = caughtErr;

checkError.getMessage(caughtErr) // 'I am a TypeError'
org.webjars.npm

Chai.js Assertion Library

Versions

Version
1.0.2