Reproduction: https://stackblitz.com/edit/github-caqski-mt3prakv?file=repro.js
import * as chai from 'chai';
const func = () => {
throw {
body: {
message: 'Custom error type',
},
};
};
chai.expect(() => func()).throws('boom!');
❯ node repro.js
TypeError: Cannot read properties of undefined (reading 'indexOf')
at Object.compatibleMessage (file:///home/projects/github-caqski-bm1zja/node_modules/chai/index.js:102:29)
at Proxy.assertThrows (file:///home/projects/github-caqski-bm1zja/node_modules/chai/index.js:2897:51)
at Proxy.methodWrapper (file:///home/projects/github-caqski-bm1zja/node_modules/chai/index.js:1721:25)
at eval (file:///home/projects/github-caqski-bm1zja/repro.js:36:19)
at _0x49baf9 (https://githubcaqskibm1zja-23jp.w-credentialless-staticblitz.com/blitz.cf284e50.js:31:819814)
at _0x464d1b.run (https://githubcaqskibm1zja-23jp.w-credentialless-staticblitz.com/blitz.cf284e50.js:31:820546)
at _0x39c6d6 (https://githubcaqskibm1zja-23jp.w-credentialless-staticblitz.com/blitz.cf284e50.js:31:835720)
at _0x3cd9a5._evaluate (https://githubcaqskibm1zja-23jp.w-credentialless-staticblitz.com/blitz.cf284e50.js:31:836069)
at _0x3cd9a5.evaluate (https://githubcaqskibm1zja-23jp.w-credentialless-staticblitz.com/blitz.cf284e50.js:31:832499)
Node.js v20.19.1
For context, a related issue is reported on Vitest vitest-dev/vitest#4559 and I created a minimal repo here.