-
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.reverse throws on error instead of invoking the callback #3112
Comments
This is expected. The general convention is to thow immediately on invalid input and pass the error to the callback if the error happens at some later point. This is not only for this function, but for a lot of other ones — invalid input should throw. |
See #2873 (comment). |
While I agree that passing non-string values to For comparison Here's some examples for current behavior: // empty string
dns.resolve("", cb); // empty string, invokes callback with ENODATA
dns.reverse("", cb); // empty string, throws EINVAL
// invalidly formatted input
dns.resolve("\x00", cb); // zero byte, invalid hostname, invokes callback with ENOTFOUND
dns.resolve("\x01", cb); // invalid hostname, invokes callback with ENODATA
dns.reverse("1.2.3", cb); // invalid IPv4, throws EINVAL |
Agreed that |
@Slayer95 But that is a logic error — you are passing something that isn't syntactically a valid IP address as an argument that accepts only IP addresses. |
Previously, if invalid input is passed to dns methods like dns.reverse, an error would be thrown. This change instead passes the error to the callback. Fixes: nodejs#3882 Fixes: nodejs#3112
Because of this and other issues, we built 🍊 Tangerine -const dns = require('dns');
+const Tangerine = require('tangerine');
-dns.reverse('1.2.3', cb); // would normally throw
+const tangerine = new Tangerine();
+const reverseCb = callbackify(tangerine.reverse);
+reverseCb('1.2.3', (err, result) => console.log(err, result)); // does not throw
// note that tangerine supports promises too!
// tangerine.reverse('1.2.3').then(console.log).catch(console.error);
// or
// await tangerine.reverse('1.2.3'); |
If an invalid IP address is passed to dns.reverse—for example, when receiving a IPv4-mapped IPv6 address like `::ffff:127.0.0.1`—it will throw instead of calling the callback with an error. See: nodejs/node#3112
If an invalid IP address is passed to dns.reverse—for example, when receiving a IPv4-mapped IPv6 address like `::ffff:127.0.0.1`—it will throw instead of calling the callback with an error. See: nodejs/node#3112
When I call
dns.reverse
with invalidip
argument (eg.false
,undefined
or an empty string) the method does not return the error with a callback likedns.resolve
does but it throws instead. See the example below.Expected output would be to see the string Should not throw but instead I see an error stack.
The text was updated successfully, but these errors were encountered: