Registry / testing / check-error

check-error

JSON →
library2.1.3jsnpmunverified

check-error is a JavaScript utility library designed for robust error inspection and comparison in both Node.js and browser environments. Currently at stable version 2.1.3, it provides functions to retrieve error information, such as constructor names and messages, and to determine compatibility between errors based on their instance, constructor, or message content. It is a foundational utility often employed within testing frameworks, particularly Chai, for asserting error conditions. Since version 2.0.0, it is an ESM-only module, requiring modern JavaScript environments (Node.js 16+, Firefox 102+, Chromium Edge+). Releases are infrequent, focusing on maintenance and modernizing the codebase to align with current JavaScript standards. Its key differentiator is providing a standardized set of primitives for error interrogation, abstracted away from environment-specific quirks, which simplifies error handling logic across different contexts. This ensures consistent behavior when dealing with various types of errors and their properties.

npm install check-error
INSTALL
IMPORT
SIG · CHECK-ERROR
C
check-error
testingjavascriptv2.1.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

checkError
import * as checkError from 'check-error';
const checkError = require('check-error');
Since v2.0.0, check-error is an ESM-only module. CommonJS `require` is no longer supported.
compatibleConstructor, getMessage
import { compatibleConstructor, getMessage } from 'check-error';
Individual utility functions can be imported as named exports for tree-shaking benefits.

Demonstrates catching different error types and using `check-error` to inspect their constructor names, messages, and compatibility with other error types.

import * as checkError from 'check-error'; class CustomError extends Error { constructor(message: string) { super(message); this.name = 'CustomError'; } } function potentiallyFailingOperation(shouldThrow: boolean, type: string = 'TypeError'): void { if (shouldThrow) { if (type === 'CustomError') { throw new CustomError('Something went wrong with custom logic.'); } else { throw new TypeError('Invalid data format received.'); } } } try { potentiallyFailingOperation(true); } catch (e: unknown) { if (e instanceof Error) { console.log(`Caught error: ${e.message}`); console.log(`Constructor name: ${checkError.getConstructorName(e)}`); console.log(`Is compatible with TypeError? ${checkError.compatibleConstructor(e, TypeError)}`); console.log(`Is compatible with message 'data format'? ${checkError.compatibleMessage(e, 'data format')}`); console.log(`Is compatible with CustomError? ${checkError.compatibleConstructor(e, CustomError)}`); } } try { potentiallyFailingOperation(true, 'CustomError'); } catch (e: unknown) { if (e instanceof Error) { console.log(`\nCaught another error: ${e.message}`); console.log(`Constructor name: ${checkError.getConstructorName(e)}`); console.log(`Is compatible with TypeError? ${checkError.compatibleConstructor(e, TypeError)}`); console.log(`Is compatible with CustomError? ${checkError.compatibleConstructor(e, CustomError)}`); } }
Debug
Known issues
breakingVersion 2.0.0 introduced a breaking change, converting the module to ESM-only. CommonJS `require()` is no longer supported.
fix
Migrate your project to use ESM `import` syntax. Ensure your Node.js environment is v16 or higher, or use modern browsers (Firefox 102+, Chromium Edge+).
affects: >=2.0.0
breakingWith the shift to ESM-only in v2.0.0, support for older environments including Node.js versions below 16, Firefox versions less than 102, and all versions of Internet Explorer and older Edge (v18 and below) was dropped.
fix
Upgrade your environment to meet the minimum requirements (Node.js >=16, Firefox >=102, Chromium Edge/Chrome/Safari latest).
affects: >=2.0.0
gotchaPrior to v2.1.2, the `compatibleMessage` function might not correctly handle invalid inputs, potentially leading to unexpected behavior or errors when comparing messages.
fix
Upgrade to version 2.1.2 or newer to ensure robust handling of invalid inputs in message comparisons.
affects: <2.1.2
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Attempting to `require()` the `check-error` package in a CommonJS environment after upgrading to v2.0.0 or later.
fix
Change `const checkError = require('check-error');` to `import * as checkError from 'check-error';` and ensure your project is configured for ESM (e.g., `"type": "module"` in package.json).
TypeError: checkError.compatibleMessage is not a function
This error is unlikely for `compatibleMessage` specifically, but if a function from the `checkError` object is not found, it implies an incorrect import or an attempt to use a non-existent method.
fix
Verify that `checkError` is correctly imported as `import * as checkError from 'check-error';` and that the method name (`compatibleMessage` or others) is spelled correctly and exists in the current version of the library.
Upgrade
Version history
2.1.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
check-error — npm install check-error · libregistry