From d2d4b4fb7cb0de88244438c4cc4160155cf280d4 Mon Sep 17 00:00:00 2001 From: Sam O'Connor Date: Fri, 15 Apr 2016 14:54:55 +1000 Subject: [PATCH] handle UV_EAI_SYSTEM and UV_EAI_MEMORY in uv_error --- base/libuv.jl | 13 ++++++++++++- base/socket.jl | 8 ++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/base/libuv.jl b/base/libuv.jl index b0116cd613d7ef..6764a2e8c23820 100644 --- a/base/libuv.jl +++ b/base/libuv.jl @@ -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 ## diff --git a/base/socket.jl b/base/socket.jl index 84e61a98d38c42..3416a0910493cf 100644 --- a/base/socket.jl +++ b/base/socket.jl @@ -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) @@ -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