Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Odd assertion error message when deep equality failed due to Error.cause #55310

Copy link
Copy link
@hi-ogawa

Description

@hi-ogawa
Issue body actions

Version

v20.18.0

Platform

Linux myhostname 6.10.10-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 12 Sep 2024 17:21:02 +0000 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

assert.deepStrictEqual(new Error("a", { cause: new Error("x") }), new Error("a", { cause: new Error("y") }))

Uncaught:
AssertionError [ERR_ASSERTION]: Values have same structure but are not reference-equal:

[Error: a]

    at REPL3:1:8
    at ContextifyScript.runInThisContext (node:vm:137:12)
    at REPLServer.defaultEval (node:repl:598:22)
    at bound (node:domain:432:15)
    at REPLServer.runBound [as eval] (node:domain:443:12)
    at REPLServer.onLine (node:repl:927:10)
    at REPLServer.emit (node:events:531:35)
    at REPLServer.emit (node:domain:488:12)
    at [_onLine] [as _onLine] (node:internal/readline/interface:417:12)
    at [_line] [as _line] (node:internal/readline/interface:888:18) {
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: [Error: a],
  expected: [Error: a],
  operator: 'deepStrictEqual'
}

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:

Uncaught:
AssertionError [ERR_ASSERTION]: Values have same structure but are not reference-equal:

[Error: a]

Additional information

I saw Node has expanded on Error instance 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    assertIssues and PRs related to the assert subsystem.Issues and PRs related to the assert subsystem.confirmed-bugIssues with confirmed bugs.Issues with confirmed bugs.errorsIssues and PRs related to JavaScript errors originated in Node.js core.Issues and PRs related to JavaScript errors originated in Node.js core.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.