Skip to content

Commit

Permalink
throw DNSError instead of UVError in getaddrinfo()
Browse files Browse the repository at this point in the history
  • Loading branch information
samoconnor committed Apr 14, 2016
1 parent a056ce2 commit 0a716ba
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion base/socket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -582,13 +582,27 @@ function getaddrinfo(cb::Function, host::ASCIIString)
end
getaddrinfo(cb::Function, host::AbstractString) = getaddrinfo(cb,ascii(host))


type DNSError <: Exception
uverror::UVError
host::AbstractString
end

function show(io::IO, e::DNSError)
print(io, "DNSError: ", e.host, ", ")
show(io, e.uverror)
end

function getaddrinfo(host::ASCIIString)
c = Condition()
getaddrinfo(host) do IP
notify(c,IP)
end
ip = wait(c)
isa(ip,UVError) && throw(ip)
if isa(ip,UVError)
@assert ip.code in [UV_EAI_NONAME, UV_EAI_AGAIN]
throw(DNSError(ip, host))
end
return ip::IPAddr
end
getaddrinfo(host::AbstractString) = getaddrinfo(ascii(host))
Expand Down

0 comments on commit 0a716ba

Please sign in to comment.