GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — assert: add deep equal check for more Error type by kylo5aby · Pull Request #51805 · nodejs/node

Conversation

@kylo5aby

@kylo5aby kylo5aby commented Feb 19, 2024

Copy link
Copy Markdown
Contributor

add deep equal check for the cases below:

  1. Error with cause property: new Error('msg', { cause: xxx })
  2. AggregateError: new AggregateError([err1, err2, ...], 'msg')

Fixes: #51793

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bricss and tonivj5 reacted with eyes emoji
All reactions
  • 👀 2 reactions
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module. labels Feb 19, 2024
BridgeAR
BridgeAR reviewed Feb 19, 2024
View reviewed changes

@BridgeAR BridgeAR left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already looking very promising!

The documentation still needs an update (we describe what properties we check in addition to enumerable ones) and I left improvement suggestions for edge cases.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/internal/util/comparisons.js Outdated

@BridgeAR BridgeAR Feb 19, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The instanceof check will work in most cases while it would not detect AggregateErrors created in a different context/realm (e.g., by creating errors in a context created by vm.createContext()). I believe it is fine to just always check for this property, in case it is not already an enumerable property.

This check would currently miss the case, if either side is an AggregateError and the other is not. That could be addressed in a similar way as I suggested above about the enumerable property.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kylo5aby reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread lib/internal/util/comparisons.js Outdated

@BridgeAR BridgeAR Feb 19, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely the right check as long the property is non-enumerable. If it is enumerable, we'd do the check twice and this could be costly and a lot of errors are created in the wild with a cause property set as an enumerable one.

In addition, we should also verify that the properties have the same enumerability. We don't yet do that for name and message, but that would be beneficial.

const cause1Enumerable = ObjectPrototypePropertyIsEnumerable(val1, 'cause');
if (cause1Enumerable !== ObjectPrototypePropertyIsEnumerable(val2, 'cause') ||
    !cause1Enumerable &&
    !innerDeepEqual(val1.cause, val2.cause, strict, memos)) {
    return false;
}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-assert-deep.js Outdated

@BridgeAR BridgeAR Feb 19, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit (just a general suggestion without need to follow-up upon): the variable names could be changed in a way that it's clearer what they stand for. E.g., this one could be:

Suggested change
const e6 = new AggregateError([e1, e2], 'Aggregate Error');
const e4duplicate = new AggregateError([e1, e2], 'Aggregate Error');

That way it would be easy to understand in the comparison that the entries are meant to be identical.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@kylo5aby
kylo5aby force-pushed the assert-error-type-compare branch 2 times, most recently from bd5f30d to bcf4e54 Compare February 20, 2024 04:13
@kylo5aby

kylo5aby commented Feb 20, 2024

Copy link
Copy Markdown
Contributor Author

@BridgeAR Thanks for your suggestion!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kylo5aby

kylo5aby commented Feb 23, 2024

Copy link
Copy Markdown
Contributor Author

@BridgeAR, I have update based on Non-Enumerable properties on Error, PTAL feel free

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

atlowChemi
atlowChemi reviewed Mar 4, 2024
View reviewed changes
Comment thread lib/internal/util/comparisons.js Outdated
Comment on lines 247 to 250

@atlowChemi atlowChemi Mar 4, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, this means now we only compare the name and message fields when they are enumerable, which specificaly opposite from the documentation, and is a breaking change...

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@kylo5aby kylo5aby Mar 5, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, this means now we only compare the name and message fields when they are enumerable, which specificaly opposite from the documentation, and is a breaking change...

FWIK, As mentioned in ECMAScript 2025, name, message, cause and errors are all non-enumerable, so in the judgement above, I just compared the attributes whether they have same enumerable property, if it's same and they are non-enumerable, then compare the attributes contents.

So if the attributes are enumerable(for example in a custom Error), the next check keyCheck will check them, in the doc change, I have just added errors, and causes attributes, and didn't change name and message, I think its doesn't break the doc, have I missed something?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@aduh95 aduh95 May 11, 2024

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it was a breaking change, I would expect we would see test failures.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@kylo5aby

kylo5aby commented Mar 18, 2024

Copy link
Copy Markdown
Contributor Author

@legendecas PTAL

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

legendecas
legendecas reviewed Mar 18, 2024
View reviewed changes

@legendecas legendecas left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding an item to the change list in the YAML frontmatter as well? Such as:

<!-- YAML
changes:
  - version: REPLACEME
    pr-url: https://github.com/nodejs/node/pull/51805
    description: Error cause property is now compared as well.
--->

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread doc/api/assert.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

legendecas
legendecas reviewed Mar 18, 2024
View reviewed changes
Comment thread test/parallel/test-assert-deep.js Outdated

@legendecas legendecas Mar 18, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertDeepAndStrictEqual only accepts two arguments.

Suggested change
assertDeepAndStrictEqual(e1, new Error('err', { cause: new Error('cause e1') }), AssertionError);
assertDeepAndStrictEqual(e1, new Error('err', { cause: new Error('cause e1') }));

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-assert-deep.js Outdated

@legendecas legendecas Mar 18, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assertDeepAndStrictEqual(e3, e3duplicate, AssertionError);
assertDeepAndStrictEqual(e3, e3duplicate);

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@legendecas legendecas added the assert Issues and PRs related to the assert subsystem. label Mar 18, 2024
@kylo5aby
kylo5aby force-pushed the assert-error-type-compare branch 3 times, most recently from f93555c to 5f48ab0 Compare March 18, 2024 10:30
legendecas
legendecas reviewed Mar 18, 2024
View reviewed changes
Comment thread doc/api/assert.md Outdated

@legendecas legendecas Mar 18, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the actual behavior unconditionally compares the errors property regardless of whether the error instance is an AggregateError or not. This could be reworded as

* [`Error`][] names, messages, causes, and errors are always compared, even if these are not enumerable properties.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@kylo5aby kylo5aby Mar 19, 2024

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved. Thanks for the reminder

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@kylo5aby
assert: add deep equal check for more Error type
7562ac6
@kylo5aby
kylo5aby force-pushed the assert-error-type-compare branch from 5f48ab0 to 7562ac6 Compare March 19, 2024 01:55
legendecas
legendecas approved these changes Mar 19, 2024
View reviewed changes
@aduh95 aduh95 added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels May 11, 2024
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label May 11, 2024
@nodejs-github-bot

nodejs-github-bot commented May 11, 2024

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/59119/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented May 12, 2024

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/59158/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented May 12, 2024

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/59181/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented May 12, 2024

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/59187/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@aduh95 aduh95 added the commit-queue PRs queued for automated landing through the Commit Queue. label May 12, 2024
@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label May 12, 2024
@nodejs-github-bot
nodejs-github-bot merged commit c8a4f70 into nodejs:main May 12, 2024
@nodejs-github-bot

nodejs-github-bot commented May 12, 2024

Copy link
Copy Markdown
Collaborator

Landed in c8a4f70

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

targos pushed a commit that referenced this pull request May 13, 2024
@kylo5aby @targos
assert: add deep equal check for more Error type
0f5716c
PR-URL: #51805
Fixes: #51793
Reviewed-By: Chengzhong Wu <[email protected]>
@targos targos mentioned this pull request May 13, 2024
v22.2.0 release proposal #52971
Merged
This was referenced Jun 12, 2024
The "cause" property of Error is ignored when matching vitest-dev/vitest#5697
Closed
fix(expect)!: check more properties for error equality vitest-dev/vitest#5876
Merged
@marco-ippolito marco-ippolito mentioned this pull request Jun 17, 2024
v20.15.0 proposal #53486
Merged
marco-ippolito pushed a commit that referenced this pull request Jun 17, 2024
@kylo5aby @marco-ippolito
assert: add deep equal check for more Error type
227093b
PR-URL: #51805
Fixes: #51793
Reviewed-By: Chengzhong Wu <[email protected]>
soophoo pushed a commit to soophoo/node that referenced this pull request Jun 20, 2024
@kylo5aby @soophoo
assert: add deep equal check for more Error type
a064469
PR-URL: nodejs#51805
Fixes: nodejs#51793
Reviewed-By: Chengzhong Wu <[email protected]>
@hi-ogawa hi-ogawa mentioned this pull request Oct 8, 2024
Odd assertion error message when deep equality failed due to Error.cause #55310
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@BridgeAR BridgeAR BridgeAR left review comments
@aduh95 aduh95 aduh95 left review comments
@atlowChemi atlowChemi atlowChemi left review comments
@legendecas legendecas legendecas approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

assert Issues and PRs related to the assert subsystem. author ready PRs with CI started, the required approvals, and no outstanding review comments. needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

deepStrictEqual and notDeepStrictEqual do not compare Error causes nor AggregateError errors arrays

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@kylo5aby @nodejs-github-bot @legendecas @BridgeAR @aduh95 @atlowChemi
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.