Repository navigation
Odd assertion error message when deep equality failed due to Error.cause #55310
Description
Activity
These also aren't reference equal AFAICT. If you deepStrictEqual the errors, they should fail.
- addedassertIssues and PRs related to the assert subsystem.Issues and PRs related to the assert subsystem.errorsIssues and PRs related to JavaScript errors originating in Node.js core.Issues and PRs related to JavaScript errors originating in Node.js core.
on Oct 8, 2024 Yeah, maybe my description wasn't clear. Assertion failure is expected, but its error message is what I wanted to point out.
Indeed,
are not reference-equalis a correct statement, but I felt it's misleading because, when usingassert.deepStrictEqual, I wouldn't usually concerned with "reference-equality".One more example here when dropping
causeon one side, it shows the same message. In this case,Values have same structuresounds misleading then.> assert.deepStrictEqual(new Error("a"), new Error("a", { cause: new Error("y") })) Uncaught: AssertionError [ERR_ASSERTION]: Values have same structure but are not reference-equal: [Error: a]
@hi-ogawa thank you for the report! This is indeed an issue with comparing errors.
causeis still relatively new and whenAssertionErrorwas written in it's current way, errors did not have that property. It's a non-enumerable property and to hide the comparederrorsstack frames the error is copied in a way that it does not contain the stack trace and cause anymore. Afterwards it's compared regularly. This now also hides thecauseand that causes the faulty above error message.This could be fixed by removing the copying and instead cutting off the stack frames after inspection but before they are compared.
Reacted by Hiroshi Ogawa and Edy SilvaReacted by Aviv Keller- addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.
on Oct 12, 2024
Version
v20.18.0
Platform
Subsystem
No response
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
always
What is the expected behavior? Why is that the expected behavior?
I'm not sure what exactly "reference-equal" means, but it sounds like it's about object identity and that might be misleading/bug.
Also ideally it would be nice if assertion diff can show the diff coming from
Error.cause.What do you see instead?
Assertion error doesn't indicate the error is due to non-matching
Error.cause:Additional information
I saw Node has expanded on
Errorinstance deep equality check #51805 and was testing it around. Vitest is trying to catch up in vitest-dev/vitest#5876 and I thought it would be a good reference to know how Node would handle this.