-
Notifications
You must be signed in to change notification settings - Fork 29.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
assert: refactor AssertionError properties #25250
Conversation
The `actual` and `expected` properties on an instance of `AssertionError` is now a getter to prevent inspecting these when inspecting the error. These values will be visible in the error message and showing them otherwise would decrease the readability of the error.
One test did not cause an assertion. By changing the test to use `assert.throws()` all tests have to throw, otherwise the test will fail.
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.
Test change/fix LGTM. No comment on the behavior change of not inspecting expected/actual. I'd need to think more on the ramifications there. (Maybe a before/after comparison to show the difference would be illuminating.)
Before:
After
|
That output might be shorter, but I don't think it's helpful at all. |
That output itself is only meant so the user known it's possible to access those properties. As I outlined above, these entries were not inspected at all until recently. Now that the extra properties are inspected by default we'd duplicate information and hide the actual error message above other information. That's why I choose this as a good middle ground. Do you have a better alternative? (It's still possible to use a custom inspection function as well) |
I can imagine the Getter/Setter output being especially misleading to newcomers. A custom inspection function that restores the old behavior should be fine. |
@cjihrig yeah, that output is indeed subpar. I believe I found another good way to display this:
|
Co-Authored-By: BridgeAR <ruben@bridgewater.de>
I just started the lite CI because there's only a typo fix and the last full CI is green.
|
The `actual` and `expected` properties on an instance of `AssertionError` is now a getter to prevent inspecting these when inspecting the error. These values will be visible in the error message and showing them otherwise would decrease the readability of the error. PR-URL: nodejs#25250 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
One test did not cause an assertion. By changing the test to use `assert.throws()` all tests have to throw, otherwise the test will fail. PR-URL: nodejs#25250 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
The `actual` and `expected` properties on an instance of `AssertionError` is now a getter to prevent inspecting these when inspecting the error. These values will be visible in the error message and showing them otherwise would decrease the readability of the error. PR-URL: #25250 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
One test did not cause an assertion. By changing the test to use `assert.throws()` all tests have to throw, otherwise the test will fail. PR-URL: #25250 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
The `actual` and `expected` properties on an instance of `AssertionError` is now a getter to prevent inspecting these when inspecting the error. These values will be visible in the error message and showing them otherwise would decrease the readability of the error. PR-URL: nodejs#25250 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
One test did not cause an assertion. By changing the test to use `assert.throws()` all tests have to throw, otherwise the test will fail. PR-URL: nodejs#25250 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
When inspecting an
AssertionError
theactual
andexpected
properties would also show up inspected (due to another recent change that made sure that extra properties on errors will always be visible).This is not really very user friendly since we already print something in the error message and showing the values again, duplicates the output. Another alternative to this would be to use a custom inspection function for
AssertionError
but I believe just moving these two properties behind getters already solved the problem well enough while keeping the other properties visible to the user.The other commit fixes a test case.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes