assert: add default operator to assert.fail()#22694
assert: add default operator to assert.fail()#22694BridgeAR wants to merge 2 commits intonodejs:masterfrom
assert.fail()#22694Conversation
This makes sure `assert.fail()` contains an operator instead of being undefined. On top of that it also fixes the `err.generatedMessage` property. Before, it was not always set correct.
|
|
|
Is there a reason to expose |
|
@Trott the |
|
PTAL @nodejs/util |
|
@nodejs/testing |
|
I see that I bring this up because I'd rather |
|
@Trott I am not sure anymore since when that is the case. I think since v8 or v9. Using e.g., |
|
@BridgeAR Thanks. Just to be clear: Not objecting. Just surprised. :-D |
|
PTAL this could use some reviews. |
lib/assert.js
Outdated
| expected, | ||
| message, | ||
| operator, | ||
| operator: operator || 'fail', |
There was a problem hiding this comment.
Does Node have a consistent way of checking for optional params or default params?
In this case the falsey check means that users can't specify it as null or "".
There was a problem hiding this comment.
No, it's often mixed and fasly values are often set to a default while in other cases only undefined is set to a default.
There was a problem hiding this comment.
This method has a mix of deprecated/legacy and new/different functionality. Would moving the operator juggle into a argLength < 2 branch with the other argLen checks be doable? That way it touches less of the overlapping code paths.
There was a problem hiding this comment.
That was done on purpose since I believe it is best to just properly do this for all cases.
Shall I maybe change the check to: operator === undefined ? 'fail' : operator?
|
PTAL |
|
|
||
| innerFail({ | ||
| if (message instanceof Error) throw message; | ||
|
|
There was a problem hiding this comment.
☝️ Should use the util for isError (internal reference) for this since it avoids the error of errors from other realms.
There was a problem hiding this comment.
Only changing this here is likely not the best way. It would have to be changed throughout assert in total or not at all. It is also sad that the util function is not a safe check as the Symbol.toStringTag could be set and isError would happily return true in some weird cases.
There was a problem hiding this comment.
Only changing this here is likely not the best way.
Ah, didn't know this was consistent with the rest of assert. A follow up would be best.
It is also sad that the util function is not a safe check as the Symbol.toStringTag could be set and isError would happily return true in some weird cases.
Oh I thought the new isNativeError was more robust.
There was a problem hiding this comment.
Oh, I missed the isNativeError somehow. We have multiple places in core where we should likely switch to this check.
|
PTAL |
This makes sure `assert.fail()` contains an operator instead of being undefined. On top of that it also fixes the `err.generatedMessage` property. Before, it was not always set correct. PR-URL: nodejs#22694 Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
|
Landed in eee5adf 🎉 |
This makes sure `assert.fail()` contains an operator instead of being undefined. On top of that it also fixes the `err.generatedMessage` property. Before, it was not always set correct. PR-URL: #22694 Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
This makes sure `assert.fail()` contains an operator instead of being undefined. On top of that it also fixes the `err.generatedMessage` property. Before, it was not always set correct. PR-URL: #22694 Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
This makes sure `assert.fail()` contains an operator instead of being undefined. On top of that it also fixes the `err.generatedMessage` property. Before, it was not always set correct. PR-URL: #22694 Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
This makes sure
assert.fail()contains an operator instead of beingundefined.
On top of that it also fixes the
err.generatedMessageproperty.Before, it was not always set correct.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes