-
Notifications
You must be signed in to change notification settings - Fork 17.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
net: Make it possible to determine if a lookup error is errNoSuchHost #28635
Comments
errNoSuchHost
/cc @mikioh |
I see there are 6 uses of unexposed Including the test file where Line 868 in c659be4
IMHO exposing this error variable and refactoring the codebase would be enough. |
Hi, I'd like to take this up if it is free |
I've missed that |
@maksadbek I'm assuming you are taking this up? |
Hi @affanv14 |
I'm a new contributor myself, I mistook you for a member, I think you may have done the same! Anyway, I'll leave this up to you. Good luck on the PR! |
You could also implement „methods“ on top of DNSError, then you don’t need an extra variable and expose the data required. |
@szuecs Do you mean a method that checks prefix of the |
Instead of storing it in a variable, you could do this yes. |
I'd like to take this up. Shall I start work on a CL, if nobody's doing it? |
Go for it. |
@gabber12 First tell us exactly how you plan to change the API. Don't send in new API via a CL. Discuss it first. Thanks. |
I am inclined to add a bool var (IsNoSuchHost)in DNSError itself(instead of doing string comparison). type DNSError struct {
Err string // description of the error
Name string // name looked for
Server string // server used
IsTimeout bool // if true, timed out; not all timeouts set this
IsTemporary bool // if true, error is temporary; not all errors set this
IsNoSuchHost bool // if true, host could not be found
} The idea would be to make IsNoSuchHost true wherever errNoSuchHost is being wrapped in DnsError. There is a todo too, to do this in dnsclient_unix.go |
If This requires adding an |
|
@jba Oh, sorry; an In this case, adding another boolean is probably the way to go since it's consistent with the existing |
Shall we go with
Personally i see similar tradeoffs in both approaches. And it really depends on the Unwrap method's consistency across std lib |
For me it's quite unclear what is meant by |
@szuecs I can understand that Timeout can be an error type, but the But overall exposing errors to user seems like a good approach to me too. |
@gabber12 You can't change the type of the |
Change https://golang.org/cl/168597 mentions this issue: |
Thanks for fixing the issue! @gabber12 does not make it more sense to have an enum style type with iota. that you have instead of the bool flags and check the type instead of the bool flags? |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I'm trying to determine whether a
net.LookupHost
fails because the DNS record doesn't exist, or because of other errors. Unfortunately,errNoSuchHost
isn't exposed fromnet
and there are no helper functions or methods to determine the type ofnet.DNSError
. This leaves me with no choice other than string parsing, which is extremely brittle.What did you expect to see?
I would expect to be able to tell
noSuchHost
errors from other errors, either by comparing with an exported error or by using a method onnet.DNSError
.What did you see instead?
It's impossible to determine whether
net.LookupHost
returned an error the DNS record doesn't exist or any other reasons without resorting to string parsing.The text was updated successfully, but these errors were encountered: