Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: chaijs/check-error
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.1.0
Choose a base ref
...
head repository: chaijs/check-error
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.1.1
Choose a head ref
  • 3 commits
  • 8 files changed
  • 2 contributors

Commits on May 8, 2024

  1. Update README.md

    koddsson authored May 8, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    thockin Tim Hockin
    Copy the full SHA
    7496fac View commit details
  2. Cleanup karma and rollup (#52)

    * remove unused karma config
    
    * remove rollup
    
    * update CI action
    koddsson authored May 8, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    bbaa93a View commit details
  3. fix: simplify error class checking (#53)

    Previously, we were unnecessarily trying to determine if the passed
    object was in fact a class which extends `Error`.
    
    We don't actually care about this, really. We just want to know if the
    `thrown` is an instance of the thing you passed.
    
    Due to this, we can simplify by simply checking that the `errorLike` is
    something with a `prototype` and assert that the `thrown` is an instance
    of it.
    43081j authored May 8, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    36f9271 View commit details
Showing with 26 additions and 245 deletions.
  1. +10 −13 .github/workflows/nodejs.yml
  2. +3 −63 README.md
  3. +1 −5 index.js
  4. +0 −19 karma.conf.cjs
  5. +0 −128 package-lock.json
  6. +1 −6 package.json
  7. +0 −11 rollup.config.js
  8. +11 −0 test/index.js
23 changes: 10 additions & 13 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build
name: Test

on:
pull_request:
@@ -7,36 +7,33 @@ on:
- main

jobs:
build:
name: Build
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Get sources
uses: actions/checkout@v1
uses: actions/checkout@v4

- name: Restore npm cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- uses: actions/cache@v2
- uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-modules-
- name: Use Node.js 16
uses: actions/setup-node@v3
- name: Use Node.js 22
uses: actions/setup-node@v4
with:
node-version: '16'
node-version: "22"

- name: Install dependencies
run: npm install

- name: Build
run: npm run build --if-present
run: npm ci

- name: Test
run: npm run test
66 changes: 3 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,15 @@
<h1 align=center>
<a href="http://chaijs.com" title="Chai Documentation">
<img alt="ChaiJS" src="http://chaijs.com/img/chai-logo.png"/> check-error
<img alt="ChaiJS" src="http://chaijs.com/img/chai-logo.png">
</a>
<br>
check-error
</h1>

<p align=center>
Error comparison and information related utility for <a href="http://nodejs.org">node</a> and the browser.
</p>

<p align=center>
<a href="./LICENSE">
<img
alt="license:mit"
src="https://img.shields.io/badge/license-mit-green.svg?style=flat-square"
/>
</a>
<a href="https://github.com/chaijs/check-error/releases">
<img
alt="tag:?"
src="https://img.shields.io/github/tag/chaijs/check-error.svg?style=flat-square"
/>
</a>

![example workflow](https://github.com/chaijs/check-error/actions/workflows/nodejs.yml/badge.svg)

<a href="https://coveralls.io/r/chaijs/check-error">
<img
alt="coverage:?"
src="https://img.shields.io/coveralls/chaijs/check-error/master.svg?style=flat-square"
/>
</a>
<a href="https://www.npmjs.com/packages/check-error">
<img
alt="npm:?"
src="https://img.shields.io/npm/v/check-error.svg?style=flat-square"
/>
</a>
<a href="https://www.npmjs.com/packages/check-error">
<img
alt="dependencies:?"
src="https://img.shields.io/npm/dm/check-error.svg?style=flat-square"
/>
</a>
<a href="">
<img
alt="devDependencies:?"
src="https://img.shields.io/david/chaijs/check-error.svg?style=flat-square"
/>
</a>
<br/>
<a href="https://saucelabs.com/u/chaijs-check-error">
<img
alt="Selenium Test Status"
src="https://saucelabs.com/browser-matrix/chaijs-check-error.svg"
/>
</a>
<br>
<a href="https://chai-slack.herokuapp.com/">
<img
alt="Join the Slack chat"
src="https://img.shields.io/badge/slack-join%20chat-E2206F.svg?style=flat-square"
/>
</a>
<a href="https://gitter.im/chaijs/chai">
<img
alt="Join the Gitter chat"
src="https://img.shields.io/badge/gitter-join%20chat-D0104D.svg?style=flat-square"
/>
</a>
</p>

## 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.
6 changes: 1 addition & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -3,10 +3,6 @@ function isErrorInstance(obj) {
return obj instanceof Error || Object.prototype.toString.call(obj) === '[object Error]';
}

function isErrorClass(obj) {
return obj === Error || (typeof obj === 'function' && obj.name === 'Error');
}

function isRegExp(obj) {
// eslint-disable-next-line prefer-reflect
return Object.prototype.toString.call(obj) === '[object RegExp]';
@@ -50,7 +46,7 @@ function compatibleConstructor(thrown, errorLike) {
if (isErrorInstance(errorLike)) {
// If `errorLike` is an instance of any error we compare their constructors
return thrown.constructor === errorLike.constructor || thrown instanceof errorLike.constructor;
} else if (isErrorClass(Object.getPrototypeOf(errorLike)) || isErrorClass(errorLike)) {
} else if ((typeof errorLike === 'object' || typeof errorLike === 'function') && errorLike.prototype) {
// If `errorLike` is a constructor that inherits from Error, we compare `thrown` to `errorLike` directly
return thrown.constructor === errorLike || thrown instanceof errorLike;
}
19 changes: 0 additions & 19 deletions karma.conf.cjs

This file was deleted.

128 changes: 0 additions & 128 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -26,11 +26,9 @@
"url": "git+ssh://git@github.com/chaijs/check-error.git"
},
"scripts": {
"build": "rollup -c rollup.config.js",
"lint": "eslint --ignore-path .gitignore index.js test/",
"prepublish": "npm run build",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"pretest": "npm run lint && npm run build",
"pretest": "npm run lint",
"test": "npm run test:node && npm run test:browser",
"test:browser": "web-test-runner",
"test:node": "mocha"
@@ -58,8 +56,6 @@
}
},
"devDependencies": {
"@rollup/plugin-commonjs": "^21.0.0",
"@rollup/plugin-node-resolve": "^13.0.5",
"@web/test-runner": "^0.17.0",
"browserify": "^13.0.0",
"browserify-istanbul": "^1.0.0",
@@ -68,7 +64,6 @@
"eslint-plugin-filenames": "^0.2.0",
"ghooks": "^1.0.1",
"mocha": "^9.1.2",
"rollup": "^2.58.0",
"semantic-release": "^4.3.5",
"simple-assert": "^2.0.0",
"validate-commit-msg": "^2.3.1"
11 changes: 0 additions & 11 deletions rollup.config.js

This file was deleted.

11 changes: 11 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -31,6 +31,17 @@ describe('checkError', function () {

assert(checkError.compatibleConstructor(errorInstance, anObject) === false);
assert(checkError.compatibleConstructor(errorInstance, aNumber) === false);

function PrototypeError() {}
PrototypeError.prototype = Object.create(Error.prototype);
assert(checkError.compatibleConstructor(new PrototypeError(), PrototypeError) === true);
assert(checkError.compatibleConstructor(new PrototypeError(), Error) === true);

// eslint-disable-next-line func-style
const WeirdNamelessError = function () {};
WeirdNamelessError.prototype = Object.create(Error.prototype);
assert(checkError.compatibleConstructor(new WeirdNamelessError(), WeirdNamelessError) === true);
assert(checkError.compatibleConstructor(new WeirdNamelessError(), Error) === true);
});

it('compatibleMessage', function () {