-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: make validateAbortSignal stricter #40657
Conversation
SGTM, but I'm surprised that no other code needs to be changed. |
cce3af9
to
4d09127
Compare
I'm not sure I see how this is an improvement, it adds a lot of code duplication to most places as usually abort signal is an optional parameter. Note that there are at least 5-10 more places you'd need to change. |
The main goal isn't really to apply any improvements as there's not much to improve, these changes are made to achieve consistency with the other validators and also allow the validator to throw an error if the value is not exactly the expected value instead of letting a specific value as |
There are quite a few validators that allow null/undefined e.g. in IMO a better solution would be to add a second parameter named |
Those custom validators are made and mostly used specifically for the subsystem they're created in, thus not making them a part of them main validators that are used all across the code base of node. The main goal here is to keep consistency of the main validators, and yes, there's a few places where they require an abort signal, such as the following; as this one creates it's own node/lib/internal/streams/add-abort-signal.js Lines 14 to 19 in e937662
|
That is not the reason that it was copied. The reason that it's copied there is for inlining, which is stated above the method. There's a discussion about it here: #36061 (comment) |
Oh, that is interesting; although the goal still stands for consistency with all the main validators, your idea of the inclusion of an optional parameter to gate the logic of whether or not the value is required is not entirely a bad approach, but it breaks the consistency with the other main validators until we change them all as well, which just changing this one seems to accomplish the goal, wdyt? |
26cd607
to
77a1d3a
Compare
We should not force-check if the passed signal is **NOT** undefined and then proceed to check whether the value is an abort signal or not as the validator won't throw an error if the value is undefined as we straight up validate the values instead of checking if they're not undefined first. This unnecessary check can be done explicitly outside of the validator to only pass the value to the validator if its not undefined.
77a1d3a
to
0cf6999
Compare
We should not force-check if the passed signal is NOT undefined and then proceed to check whether the value is an abort signal or not as the validator won't throw an error if the value is undefined as we straight up validate the values instead of checking if they're not undefined first. This unnecessary check can be done explicitly outside of the validator to only pass the value to the validator if its not undefined.