-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
getaddrinfo throws UVError "unknown node or service" #14972
Comments
Returning a |
No. There is no difference between
That is why this issue cites |
I agree about |
How should the reason for the failure be handled? e.g. |
|
@vtjnash, I'm not opposed to sticking with I agree that there are APIs like this where, for some (or most?) users, this is a fatal error and they don't want to get bogged down in error handling. The error should not be a If error types for are added and documented for Perhaps that rule could be refined to take into account the idea of a "simple script that expects the network to be available". The same issue is present in the file access API. e.g. this will work every time for a lot of users: Maybe the rule could be: "any Julia API that requires you to [use try/catch] in when dealing with simple local resources is a broken API. APIs that deal with remote or shared resources may use exceptions to model re-tryable situations that occur infrequently". |
Indeed, returning an exception allows giving an error code, which But regarding rules about exceptions, the local vs. remote distinction isn't the real underlying reason, though it's a good approximation. I would say what could justify that a function raises an exception in the absence of programming error is the unpredictability of the failure. Indeed, the particularity of I/O and network calls is that something might fail even if you checked that it worked right before doing the call: the network might have been disconnected, or a file removed in the meantime. @StefanKarpinski Would you be fine with adapting the rules about exceptions and mentioning them in the manual? The quote from you @samoconnor gives above doesn't appear to reflect the current state of the Julia APIs, as can be seen from the fact that e.g. |
I don't think there is agreement that APIs should not throw exceptions. Further I don't understand why this should be linked to whether its network code or local code. |
We'd have to get Stefan's intention when he wrote that, but to me "control flow" means in python you might do something like this:
which can be a valid approach (though this particular example isn't really). In julia we wouldn't use exceptions to do that kind of thing. ...that said, exceptions are part of the language. They have performance issues, but when you're doing network IO that's not really an issue... so what is?
I would argue this IS an exceptional case, not part of "control flow"... and it is something the caller is going to have to handle (there's not just one way to handle it which the package can just implement). If you conceal it in a Nullable you lose the the context of the error, the stacktrace etc. Another approach (that the Scala codebase at my current work uses) is to return Eithers or (Future) Success/Failure throughout... but I think this is a tough sell in a non-functional language, and you also lose the context as discussed above (in the cases where there were "unexpected" Failures i.e. debugging is a PITA). TLDR: Exceptions are just really useful and well-understood. |
@hayd: I'd say that's a pretty reasonable interpretation of what I meant. Also keep in mind that we're figuring out how we do things here. At this point it's pretty clear that "the Julian way" does not include using exceptions for basic control flow, but DNS errors are a much tougher call. Of course, exceptions have predictability problems that give me pause (see #7026), but if we had a solution to those, this would be fine, and even without it, it's largely unproblematic. |
@StefanKarpinski I am very interested to know your opinion of the Midori examples, see: #7026 (comment). (Midori makes an explicit distinction between dealing with bugs (abandonment) vs recoverable exceptions and has a mandatory call site keyword similar to the "chain of custody" idea in #7026.) While stuff is in the process of being figured out, could some general rules be agreed on? e.g.
|
@samoconnor: I'm reading through this. So far very interesting – thanks for bringing it to my attention. |
See related: #15514 |
samoconnor@0a716ba adds a julia> getaddrinfo("google.com")
ERROR: DNSError: google.com, getaddrinfo callback: unknown node or service (EAI_NONAME) @vtjnash would you support a PR along these lines? |
i would go with it. i'm still undecided on whether to change it to use direct return of a nullable error type. in the meantime, providing clearer error messages i think is still a worthwhile investment. |
@vtjnash #15879 is now passing Travis and AV. It now also emits Is there anything you'd like tweaked before merging? (or feel free to merge and tweak to your taste yourself if you think that'll save time). |
FWIW, it looks like a good solution here would be to return something similar to Rust's |
I believe I am hitting this when trying to use HTTP.jl to make calls in a containerized setting. |
The manual says only: "getaddrinfo(host) Gets the IP address of the host (may have to do a DNS lookup)".
The current implementation of
getaddrinfo
throwsUVError
if the host can't be found (including in cases where the cause is a temporary network outage).@StefanKarpinski wrote:
In this case there is no precondition violation, either I'm looking up an address that doesn't exist (yet/anymore) or I'm looking up a valid address but can't contact the DNS at the moment.
What pattern is preferred by the core Julia devs for an API that can fail even when the precondition is met? Is there an API that can be held up as a "good example" of this pattern?
Should
getaddrinfo
returnBool
and fill in a IPv4 object passed as an arg?Should the return be
nothing
if the lookup fails?Should
getaddrinfo
return some kind ofIPv4Request
object that has fieldsok::Bool
,error_info::String
andresult::Nullable{IPv4}
?Background: I'm trying to figure out what is the best way to deal with exceptions in the AWSCore.jl API. (where "best" == most consistent with the philosophy and style of Julia). So I'm looking at Base for examples of how error conditions should be handled.
The text was updated successfully, but these errors were encountered: