Uh oh!
There was an error while loading. Please reload this page.
assert: add deep equal check for more Error type - #51805
Conversation
BridgeAR
left a comment
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
constcause1Enumerable=ObjectPrototypePropertyIsEnumerable(val1,'cause');if(cause1Enumerable!==ObjectPrototypePropertyIsEnumerable(val2,'cause')||!cause1Enumerable&&!innerDeepEqual(val1.cause,val2.cause,strict,memos)){returnfalse;}There was a problem hiding this comment.
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:
| conste6=newAggregateError([e1,e2],'Aggregate Error'); | |
| conste4duplicate=newAggregateError([e1,e2],'Aggregate Error'); |
That way it would be easy to understand in the comparison that the entries are meant to be identical.
bd5f30d to
bcf4e54Comparekylo5aby
commented
Feb 20, 2024
@BridgeAR Thanks for your suggestion! |
kylo5aby
commented
Feb 23, 2024
@BridgeAR, I have update based on Non-Enumerable properties on Error, PTAL feel free |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
As far as I can tell, this means now we only compare the
nameandmessagefields 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?
There was a problem hiding this comment.
If it was a breaking change, I would expect we would see test failures.
kylo5aby
commented
Mar 18, 2024
@legendecas PTAL |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
assertDeepAndStrictEqual only accepts two arguments.
| assertDeepAndStrictEqual(e1,newError('err',{cause: newError('cause e1')}),AssertionError); | |
| assertDeepAndStrictEqual(e1,newError('err',{cause: newError('cause e1')})); |
There was a problem hiding this comment.
| assertDeepAndStrictEqual(e3,e3duplicate,AssertionError); | |
| assertDeepAndStrictEqual(e3,e3duplicate); |
f93555c to
5f48ab0CompareThere was a problem hiding this comment.
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.
There was a problem hiding this comment.
Resolved. Thanks for the reminder
5f48ab0 to
7562ac6Comparenodejs-github-bot
commented
May 11, 2024
nodejs-github-bot
commented
May 12, 2024
nodejs-github-bot
commented
May 12, 2024
nodejs-github-bot
commented
May 12, 2024
nodejs-github-bot
commented
May 12, 2024
Landed in c8a4f70 |
PR-URL: nodejs#51805Fixes: nodejs#51793 Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
add deep equal check for the cases below:
causeproperty:new Error('msg', { cause: xxx })new AggregateError([err1, err2, ...], 'msg')Fixes: #51793