
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
check-error
Advanced tools
Error comparison and information related utility for node and the browser.
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.
check-error is available on npm. To install it, type:
$ npm install check-error
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>
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.import * as checkError 'check-error';
import * as checkError 'check-error';
const funcThatThrows = function() { throw new TypeError('I am a TypeError') };
let caughtErr;
try {
funcThatThrows();
} catch(e) {
caughtErr = e;
}
const sameInstance = caughtErr;
checkError.compatibleInstance(caughtErr, sameInstance); // true
checkError.compatibleInstance(caughtErr, new TypeError('Another error')); // false
import * as checkError 'check-error';
const funcThatThrows = function() { throw new TypeError('I am a TypeError') };
let caughtErr;
try {
funcThatThrows();
} catch(e) {
caughtErr = e;
}
checkError.compatibleConstructor(caughtErr, Error); // true
checkError.compatibleConstructor(caughtErr, TypeError); // true
checkError.compatibleConstructor(caughtErr, RangeError); // false
import * as checkError 'check-error';
const funcThatThrows = function() { throw new TypeError('I am a TypeError') };
let caughtErr;
try {
funcThatThrows();
} catch(e) {
caughtErr = e;
}
const 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
import * as checkError 'check-error';
const funcThatThrows = function() { throw new TypeError('I am a TypeError') };
let caughtErr;
try {
funcThatThrows();
} catch(e) {
caughtErr = e;
}
const sameInstance = caughtErr;
checkError.getConstructorName(caughtErr) // 'TypeError'
import * as checkError 'check-error';
const funcThatThrows = function() { throw new TypeError('I am a TypeError') };
let caughtErr;
try {
funcThatThrows();
} catch(e) {
caughtErr = e;
}
const sameInstance = caughtErr;
checkError.getMessage(caughtErr) // 'I am a TypeError'
Chai is an assertion library that can be paired with any testing framework. It includes similar functionalities for checking errors through its assert, expect, and should interfaces. Chai provides a more extensive set of assertions for various use cases compared to check-error.
Jest is a testing framework that includes its own set of assertion methods for checking errors. It offers a built-in expect function that can be used to test for specific error types and messages. Jest provides a more integrated testing solution with built-in mocking and spying capabilities in addition to error checking.
The assert module is built into Node.js and provides a simple set of assertion tests that can be used to test invariants. It includes assert.throws and assert.doesNotThrow methods for checking errors. While it is less feature-rich than check-error, it does not require any additional dependencies.
FAQs
Error comparison and information related utility for node and the browser
The npm package check-error receives a total of 31,722,531 weekly downloads. As such, check-error popularity was classified as popular.
We found that check-error demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.