-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
dns: Refactor forEach to map #5803
Conversation
Maybe I missed the memo but why is Array#map better than Array#forEach? Aside, mixing several style changes in a single commit is kind of meh. |
@bnoordhuis I tried to do as little unrelated changes as possible here and only edited one function. Basically, the code was creating a new array, and then pushing to it in a loop and returning the results which is what I think |
|
@ChALkeR care to review? |
|
||
throw new Error('IP address is not properly formatted: ' + serv); | ||
}); | ||
|
||
var r = cares.setServers(newSet); | ||
const errorNumber = cares.setServers(newSet); |
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.
Does this always return a number?
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.
Yes, it does. This is why I think r
was confusing. It's SetServers
in cares_wrap.cc
which does:
args.GetReturnValue().Set(err);
where err
is either 0 for no error or a non-zero value for an error, where err
is an int.
-1 to all the variable renaming. It makes this harder to review alongside the other changes. |
Fair enough, I'll revert all the naming changes except for |
I think |
|
||
var match = serv.match(/\[(.*)\](:\d+)?/); | ||
if (ipVersion !== 0) | ||
return [ver, serv]; |
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.
Where did ver
come from? ;-)
384dfdc
to
3747a13
Compare
@ChALkeR I reverted most of the variable names as it seems people didn't like that change being included in this one. Sorry for the mess :) |
|
||
if (ver) | ||
return newSet.push([ver, s]); | ||
if (ipVersion) |
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 inconsistent with if (ipVersion !== 0)
in two places above.
@ChALkeR fixed. Thanks. |
LGTM if the CI is happy. |
@benjamingr ... looks like this needs a rebase and update. |
Yeah, on top of my other (now landed) PR, I'll do it today and tomorrow and re-run CI, thanks :) |
aa63331
to
1a96099
Compare
1a96099
to
568b586
Compare
// reset the servers to the old servers, because ares probably unset them | ||
cares.setServers(orig.join(',')); | ||
|
||
var err = cares.strerror(r); | ||
throw new Error(`c-ares failed to set servers: "${err}" [${servers}]`); | ||
|
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.
Unrelated newline? Is that accidental?
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.
Yeah, that's because during the rebase I'll fix it.
LGTM |
568b586
to
797a272
Compare
Looks like there's a linting issue on this: https://ci.nodejs.org/job/node-test-linter/1770/console |
Yeah, pushed a fix, any idea about the other issue? Is that just the build trolling? |
Not sure, looks like an unrelated timeout. It's the first time I've seen it tho. /cc @Trott |
You also pushed a |
Refactor a forEach to a `map` in the `setServers` function of the dns module - simplifying the code. In addition, use more descriptive variable names and `const` over `var` where possible. PR-URL: nodejs#5803 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
b40d64c
to
669db03
Compare
Thanks, running a new CI https://ci.nodejs.org/job/node-test-pull-request/2024/ |
One failure in CI looks unrelated but can you please verify. |
https://ci.nodejs.org/job/node-test-binary-arm/1451/RUN_SUBSET=5,nodes=pi1-raspbian-wheezy/console @jasnell looks unrelated, pinging @nodejs/build so they see the link. |
Refactor a forEach to a `map` in the `setServers` function of the dns module - simplifying the code. In addition, use more descriptive variable names and `const` over `var` where possible. PR-URL: nodejs#5803 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Landed in 4985c34 thanks! |
Refactor a forEach to a `map` in the `setServers` function of the dns module - simplifying the code. In addition, use more descriptive variable names and `const` over `var` where possible. PR-URL: #5803 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Refactor a forEach to a `map` in the `setServers` function of the dns module - simplifying the code. In addition, use more descriptive variable names and `const` over `var` where possible. PR-URL: #5803 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
@benjamingr this patch does not land cleanly. Would you be able to backport it? |
@thealphanerd I'm not sure we should backport it and in either case it's just a code cleanup. I can backport it though. I'll try to do a sweep through my PRs to master and do all the backporting to 5.x and 4.x next weekend. |
thanks @benjamingr |
Pull Request check-list
Affected core subsystem(s)
dns
Description of change
This is (as suggested) a more modular take on - #5762 , adding the changes one by one and making sure they're less objectionable. Making more smaller PRs.
Refactor a forEach to a
map
in thesetServers
function of thedns module - simplifying the code. In addition, use more descriptive
variable names and
const
overvar
where possible.