-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
lib: throw a special error in internal/assert #26635
Conversation
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.
LGTM, I would just rather not use the helper function.
name: 'Error [ERR_INTERNAL_ASSERTION]', | ||
code: 'ERR_INTERNAL_ASSERTION' | ||
}); | ||
} |
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 would rather not add this helper function in common. Common is AFAIC pretty overboarded.
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.
That's where common.expectsError
is...I guess we could move these and other expectsSomething
to one file when the time comes
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.
Also, surprisingly, test/common.js
is even less than 1000 lines? That's even smaller than a lot of our tests :S
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.
It's not about having a lot of lines but this file is loaded for every single test file and I would rather completely get rid of something that we always use.
Having something more specific would be fine but I actually doubt that this will often be tested for and currently there are only for places in which this helper would be used in.
About common.expectsError()
it is already used significantly less as we can always use assert.throws()
instead. Only callbacks should always use common.expectsError()
.
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.
Do you strongly prefer the helper function? To me it still does not seem necessary.
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 consensus is you don't need to validate the message
of errors in more then one place (in this case test/message/internal_assert.js
is enough), so there's no need for the value that you are DRYing in the first place.
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.
@refack This is special in that the message is what we want to test for in the test cases, because the code is constant across all internal assertions and we intentionally do not give error codes for assertions coming out of completely different type of bugs.
For instance, we want to verify that we tell the user handle must be a FSEvent
if the user monkey patches watcher._handle
incorrectly, but we do not want to create a code for that special type of bugs because the user is simply violating the API contract and it gives us little to classify all these violations and assign permanent error codes instead of just telling them no. However it's still useful to verify that we hint something helpful in the message.
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 think it's important to make sure we provide useful information in the assertions, even for our own sake - just making sure that we say "you are hitting a bug, please open an issue" is not enough, see all the useless error messages in #26798 before #26859 (though that one is not verifiable in user land).
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 special in that the message is what we want to test for in the test cases,
What I mean there's no need to validate the message formatting mechanism more then once.
For example you can store the specific prefix behind a Symbol
field and validate just it.
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.
My concern about common/index
is only about the requirement of a common helper function. I would love to remove the requirement for our test files at some point.
I already gave my LG, so from my side this can land as is.
52c6873
to
ac92395
Compare
Rebased & addressed doc reviews: https://ci.nodejs.org/job/node-test-pull-request/21638/ |
@joyeecheung this requires a rebase. |
ac92395
to
f38b910
Compare
Made the paths in message tests play nice with Windows |
I'm thinking about this some more... I believe this is a big change that deserves some design review. For example:
So essentially IMO this is a semver-major change... |
TBH this is just a drive-by change for me, what I had in mind is more along the lines of “oh, this is entirely internal, why not just say something more helpful, we should be free to change this and are totally free to regret about it if it’s a bad idea”. I don’t personally think it’s worth the time to be pedantic about it, so if anyone has any strong opinions about what’s changed here, feel free to take it on. |
@refack I definitely disagree that this is semver-major. If anyone runs into one of these assertions, something must be seriously broken. We only use the assertions as safeguards without documenting any of them as in giving a guarantee for the error message. It is also out of scope of this PR if the exceptions are recoverable or not. That could be looked at in another PR or issue but that's definitely something independent for me. |
@refack is your comment blocking? If not, I'd actually like to go ahead and land this as is. |
I would actually like to land this some time soon. @refack is your comment blocking? |
I'll land this on the 16.04. if there's no hard objection until then. // @refack |
Instead of using the public AssertionError, use a simplified error that describes potential causes of these assertions and suggests the user to open an issue. PR-URL: nodejs#26635 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
|
I had to force push this out again, since the tests failed due to recent changes. |
Instead of using the public AssertionError, use a simplified error that describes potential causes of these assertions and suggests the user to open an issue.
9888451
to
98e873f
Compare
Landed in b9f1e57 🎉 |
Instead of using the public AssertionError, use a simplified error that describes potential causes of these assertions and suggests the user to open an issue. PR-URL: nodejs#26635 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Instead of using the public AssertionError, use a simplified error that describes potential causes of these assertions and suggests the user to open an issue. PR-URL: #26635 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Instead of using the public AssertionError, use a simplified
error that describes potential causes of these assertions
and suggests the user to open an issue.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes