Skip to content

Commit

Permalink
handle UV_EAI_SYSTEM and UV_EAI_MEMORY in uv_error
Browse files Browse the repository at this point in the history
  • Loading branch information
samoconnor committed Apr 15, 2016
1 parent 0a716ba commit d2d4b4f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 12 additions & 1 deletion base/libuv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,18 @@ struverror(err::UVError) = bytestring(ccall(:uv_strerror,Cstring,(Int32,),err.co
uverrorname(err::UVError) = bytestring(ccall(:uv_err_name,Cstring,(Int32,),err.code))

uv_error(prefix::Symbol, c::Integer) = uv_error(string(prefix),c)
uv_error(prefix::AbstractString, c::Integer) = c < 0 ? throw(UVError(prefix,c)) : nothing

function uv_error(prefix::AbstractString, c::Integer)
if c == UV_EAI_SYSTEM
throw(SystemError(prefix))
elseif c == UV_EAI_MEMORY
throw(OutOfMemoryError())
elseif c < 0
throw(UVError(prefix,c))
end
return nothing
end

show(io::IO, e::UVError) = print(io, e.prefix*": "*struverror(e)*" ("*uverrorname(e)*")")

## event loop ##
Expand Down
8 changes: 4 additions & 4 deletions base/socket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,9 @@ type DNSError <: Exception
host::AbstractString
end

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

function getaddrinfo(host::ASCIIString)
Expand All @@ -600,7 +600,7 @@ function getaddrinfo(host::ASCIIString)
end
ip = wait(c)
if isa(ip,UVError)
@assert ip.code in [UV_EAI_NONAME, UV_EAI_AGAIN]
@assert ip.code in [UV_EAI_NONAME, UV_EAI_AGAIN, UV_EAI_FAIL, UV_EAI_NODATA]
throw(DNSError(ip, host))
end
return ip::IPAddr
Expand Down

0 comments on commit d2d4b4f

Please sign in to comment.