Skip to content
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

RFC: rename UVError to IOError #28287

Merged
merged 1 commit into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ end
@deprecate readstring(filename::AbstractString) read(filename, String)
@deprecate readstring(cmd::AbstractCmd) read(cmd, String)

@deprecate_binding UVError IOError false

# issue #11310
# remove "parametric method syntax" deprecation in julia-syntax.scm

Expand Down
2 changes: 1 addition & 1 deletion base/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ retry(f, delays=fill(5.0, 3))
retry(f, delays=rand(5:10, 2))
retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000))
retry(http_get, check=(s,e)->e.status == "503")(url)
retry(read, check=(s,e)->isa(e, UVError))(io, 128; all=false)
retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false)
```
"""
function retry(f::Function; delays=ExponentialBackOff(), check=nothing)
Expand Down
4 changes: 2 additions & 2 deletions base/event.jl
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ mutable struct AsyncCondition
#TODO: this codepath is currently not tested
Libc.free(this.handle)
this.handle = C_NULL
throw(UVError("uv_async_init", err))
throw(_UVError("uv_async_init", err))
end
return this
end
Expand Down Expand Up @@ -353,7 +353,7 @@ mutable struct Timer
#TODO: this codepath is currently not tested
Libc.free(this.handle)
this.handle = C_NULL
throw(UVError("uv_timer_init", err))
throw(_UVError("uv_timer_init", err))
end

associate_julia_struct(this.handle, this)
Expand Down
4 changes: 2 additions & 2 deletions base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ julia> rm("my", recursive=true)
julia> rm("this_file_does_not_exist", force=true)

julia> rm("this_file_does_not_exist")
ERROR: unlink: no such file or directory (ENOENT)
ERROR: IOError: unlink: no such file or directory (ENOENT)
Stacktrace:
[...]
```
Expand All @@ -252,7 +252,7 @@ function rm(path::AbstractString; force::Bool=false, recursive::Bool=false)
end
unlink(path)
catch err
if force && isa(err, UVError) && err.code==Base.UV_ENOENT
if force && isa(err, IOError) && err.code==Base.UV_ENOENT
return
end
rethrow()
Expand Down
2 changes: 1 addition & 1 deletion base/filesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export File,
S_IROTH, S_IWOTH, S_IXOTH, S_IRWXO

import .Base:
UVError, _sizeof_uv_fs, check_open, close, eof, eventloop, fd, isopen,
IOError, _UVError, _sizeof_uv_fs, check_open, close, eof, eventloop, fd, isopen,
bytesavailable, position, read, read!, readavailable, seek, seekend, show,
skip, stat, unsafe_read, unsafe_write, write, transcode, uv_error,
rawhandle, OS_HANDLE, INVALID_OS_HANDLE
Expand Down
2 changes: 1 addition & 1 deletion base/initdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ end
function current_project()
dir = try pwd()
catch err
err isa UVError || rethrow(err)
err isa IOError || rethrow(err)
return nothing
end
return current_project(dir)
Expand Down
18 changes: 11 additions & 7 deletions base/libuv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,24 @@ end

## Libuv error handling ##

struct UVError <: Exception
prefix::AbstractString
struct IOError <: Exception
msg::AbstractString
code::Int32
UVError(p::AbstractString, code::Integer) = new(p,code)
IOError(msg::AbstractString, code::Integer) = new(msg, code)
end

showerror(io::IO, e::IOError) = print(io, "IOError: ", e.msg)

function _UVError(pfx::AbstractString, code::Integer)
code = Int32(code)
IOError(string(pfx, ": ", struverror(code), " (", uverrorname(code), ")"), code)
end

struverror(err::Int32) = unsafe_string(ccall(:uv_strerror,Cstring,(Int32,),err))
struverror(err::UVError) = struverror(err.code)
uverrorname(err::Int32) = unsafe_string(ccall(:uv_err_name,Cstring,(Int32,),err))
uverrorname(err::UVError) = uverrorname(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
show(io::IO, e::UVError) = print(io, e.prefix*": "*struverror(e)*" ("*uverrorname(e)*")")
uv_error(prefix::AbstractString, c::Integer) = c < 0 ? throw(_UVError(prefix,c)) : nothing

## event loop ##

Expand Down
6 changes: 3 additions & 3 deletions base/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ function _jl_spawn(file, argv, cmd::Cmd, stdio)
uv_jl_return_spawn::Ptr{Cvoid})
if error != 0
ccall(:jl_forceclose_uv, Cvoid, (Ptr{Cvoid},), proc)
throw(UVError("could not spawn " * string(cmd), error))
throw(_UVError("could not spawn " * string(cmd), error))
end
return proc
end
Expand Down Expand Up @@ -687,7 +687,7 @@ function test_success(proc::Process)
@assert process_exited(proc)
if proc.exitcode < 0
#TODO: this codepath is not currently tested
throw(UVError("could not start process $(string(proc.cmd))", proc.exitcode))
throw(_UVError("could not start process $(string(proc.cmd))", proc.exitcode))
end
proc.exitcode == 0 && (proc.termsignal == 0 || proc.termsignal == SIGPIPE)
end
Expand Down Expand Up @@ -743,7 +743,7 @@ function kill(p::Process, signum::Integer)
@assert p.handle != C_NULL
err = ccall(:uv_process_kill, Int32, (Ptr{Cvoid}, Int32), p.handle, signum)
if err != 0 && err != UV_ESRCH
throw(UVError("kill", err))
throw(_UVError("kill", err))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion base/stat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ macro stat_call(sym, arg1type, arg)
return quote
stat_buf = zeros(UInt8, ccall(:jl_sizeof_stat, Int32, ()))
r = ccall($(Expr(:quote, sym)), Int32, ($(esc(arg1type)), Ptr{UInt8}), $(esc(arg)), stat_buf)
r == 0 || r == Base.UV_ENOENT || r == Base.UV_ENOTDIR || throw(UVError("stat", r))
r == 0 || r == Base.UV_ENOENT || r == Base.UV_ENOTDIR || throw(_UVError("stat", r))
st = StatStruct(stat_buf)
if ispath(st) != (r == 0)
error("stat returned zero type for a valid path")
Expand Down
4 changes: 2 additions & 2 deletions base/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ function uv_readcb(handle::Ptr{Cvoid}, nread::Cssize_t, buf::Ptr{Cvoid})
# This is a fatal connection error. Shutdown requests as per the usual
# close function won't work and libuv will fail with an assertion failure
ccall(:jl_forceclose_uv, Cvoid, (Ptr{Cvoid},), stream)
notify_error(stream.readnotify, UVError("read", nread))
notify_error(stream.readnotify, _UVError("read", nread))
end
else
notify_filled(stream.buffer, nread)
Expand Down Expand Up @@ -882,7 +882,7 @@ function uv_writecb_task(req::Ptr{Cvoid}, status::Cint)
uv_req_set_data(req, C_NULL) # let the Task know we got the writecb
t = unsafe_pointer_to_objref(d)::Task
if status < 0
err = UVError("write", status)
err = _UVError("write", status)
schedule(t, err, error=true)
else
schedule(t)
Expand Down
26 changes: 13 additions & 13 deletions stdlib/FileWatching/src/FileWatching.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export
PollingFileWatcher,
FDWatcher

import Base: @handle_as, wait, close, eventloop, notify_error, stream_wait,
_sizeof_uv_poll, _sizeof_uv_fs_poll, _sizeof_uv_fs_event, _uv_hook_close, uv_error, UVError,
import Base: @handle_as, wait, close, eventloop, notify_error, stream_wait, IOError,
_sizeof_uv_poll, _sizeof_uv_fs_poll, _sizeof_uv_fs_event, _uv_hook_close, uv_error, _UVError,
associate_julia_struct, disassociate_julia_struct, isreadable, iswritable, |
import Base.Filesystem.StatStruct
if Sys.iswindows()
Expand Down Expand Up @@ -85,7 +85,7 @@ mutable struct FileMonitor
err = ccall(:uv_fs_event_init, Cint, (Ptr{Cvoid}, Ptr{Cvoid}), eventloop(), handle)
if err != 0
Libc.free(handle)
throw(UVError("FileMonitor", err))
throw(_UVError("FileMonitor", err))
end
finalizer(uvfinalize, this)
return this
Expand All @@ -95,7 +95,7 @@ end

mutable struct FolderMonitor
handle::Ptr{Cvoid}
notify::Channel{Any} # eltype = Union{Pair{String, FileEvent}, UVError}
notify::Channel{Any} # eltype = Union{Pair{String, FileEvent}, IOError}
open::Bool
FolderMonitor(folder::AbstractString) = FolderMonitor(String(folder))
function FolderMonitor(folder::String)
Expand All @@ -105,7 +105,7 @@ mutable struct FolderMonitor
err = ccall(:uv_fs_event_init, Cint, (Ptr{Cvoid}, Ptr{Cvoid}), eventloop(), handle)
if err != 0
Libc.free(handle)
throw(UVError("FolderMonitor", err))
throw(_UVError("FolderMonitor", err))
end
this.open = true
finalizer(uvfinalize, this)
Expand All @@ -132,7 +132,7 @@ mutable struct PollingFileWatcher
err = ccall(:uv_fs_poll_init, Int32, (Ptr{Cvoid}, Ptr{Cvoid}), eventloop(), handle)
if err != 0
Libc.free(handle)
throw(UVError("PollingFileWatcher", err))
throw(_UVError("PollingFileWatcher", err))
end
finalizer(uvfinalize, this)
return this
Expand Down Expand Up @@ -180,7 +180,7 @@ mutable struct _FDWatcher
err = ccall(:uv_poll_init, Int32, (Ptr{Cvoid}, Ptr{Cvoid}, RawFD), eventloop(), handle, fd)
if err != 0
Libc.free(handle)
throw(UVError("FDWatcher", err))
throw(_UVError("FDWatcher", err))
end
finalizer(uvfinalize, this)
FDWatchers[fdnum] = this
Expand Down Expand Up @@ -229,7 +229,7 @@ mutable struct _FDWatcher
eventloop(), handle, fd)
if err != 0
Libc.free(handle)
throw(UVError("FDWatcher", err))
throw(_UVError("FDWatcher", err))
end
finalizer(uvfinalize, this)
return this
Expand Down Expand Up @@ -314,7 +314,7 @@ end
function uv_fseventscb_file(handle::Ptr{Cvoid}, filename::Ptr, events::Int32, status::Int32)
t = @handle_as handle FileMonitor
if status != 0
notify_error(t.notify, UVError("FileMonitor", status))
notify_error(t.notify, _UVError("FileMonitor", status))
else
t.events |= events
notify(t.notify, FileEvent(events))
Expand All @@ -325,7 +325,7 @@ end
function uv_fseventscb_folder(handle::Ptr{Cvoid}, filename::Ptr, events::Int32, status::Int32)
t = @handle_as handle FolderMonitor
if status != 0
put!(t.notify, UVError("FolderMonitor", status))
put!(t.notify, _UVError("FolderMonitor", status))
else
fname = (filename == C_NULL) ? "" : unsafe_string(convert(Cstring, filename))
put!(t.notify, fname => FileEvent(events))
Expand All @@ -336,7 +336,7 @@ end
function uv_pollcb(handle::Ptr{Cvoid}, status::Int32, events::Int32)
t = @handle_as handle _FDWatcher
if status != 0
notify_error(t.notify, UVError("FDWatcher", status))
notify_error(t.notify, _UVError("FDWatcher", status))
else
t.events |= events
if t.active[1] || t.active[2]
Expand Down Expand Up @@ -491,7 +491,7 @@ function wait(pfw::PollingFileWatcher)
if pfw.handle == C_NULL
return prevstat, EOFError()
elseif pfw.curr_error != 0
return prevstat, UVError("PollingFileWatcher", pfw.curr_error)
return prevstat, _UVError("PollingFileWatcher", pfw.curr_error)
else
return prevstat, pfw.curr_stat
end
Expand Down Expand Up @@ -685,7 +685,7 @@ function poll_file(s::AbstractString, interval_seconds::Real=5.007, timeout_s::R
@async (sleep(timeout_s); close(pfw))
end
statdiff = wait(pfw)
if isa(statdiff[2], UVError)
if isa(statdiff[2], IOError)
# file didn't initially exist, continue watching for it to be created (or the error to change)
statdiff = wait(pfw)
end
Expand Down
4 changes: 2 additions & 2 deletions stdlib/FileWatching/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,9 @@ let changes = []
@test all(x -> (isa(x, Pair) && x[1] == F_PATH && (x[2].changed ⊻ x[2].renamed)), changes) || changes
end

@test_throws(Base.UVError("FileMonitor (start)", Base.UV_ENOENT),
@test_throws(Base._UVError("FileMonitor (start)", Base.UV_ENOENT),
watch_file("____nonexistent_file", 10))
@test_throws(Base.UVError("FolderMonitor (start)", Base.UV_ENOENT),
@test_throws(Base._UVError("FolderMonitor (start)", Base.UV_ENOENT),
watch_folder("____nonexistent_file", 10))
@test(@elapsed(
@test(poll_file("____nonexistent_file", 1, 3.1) ===
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Mmap/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ close(s); finalize(m); m=nothing; GC.gc()

s = open(file, "r")
close(s)
@test_throws Base.UVError Mmap.mmap(s) # closed IOStream
@test_throws Base.IOError Mmap.mmap(s) # closed IOStream
@test_throws ArgumentError Mmap.mmap(s,Vector{UInt8},12,0) # closed IOStream
@test_throws SystemError Mmap.mmap("")

Expand Down
2 changes: 1 addition & 1 deletion stdlib/Sockets/src/PipeServer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function bind(server::PipeServer, name::AbstractString)
if err != 0
if err != UV_EADDRINUSE && err != UV_EACCES
#TODO: this codepath is currently not tested
throw(UVError("bind",err))
throw(_UVError("bind",err))
else
return false
end
Expand Down
13 changes: 6 additions & 7 deletions stdlib/Sockets/src/Sockets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export
import Base: isless, show, print, parse, bind, convert, isreadable, iswritable, alloc_buf_hook, _uv_hook_close

using Base: LibuvStream, LibuvServer, PipeEndpoint, @handle_as, uv_error, associate_julia_struct, uvfinalize,
notify_error, stream_wait, uv_req_data, uv_req_set_data, preserve_handle, unpreserve_handle, UVError,
notify_error, stream_wait, uv_req_data, uv_req_set_data, preserve_handle, unpreserve_handle, _UVError, IOError,
eventloop, StatusUninit, StatusInit, StatusConnecting, StatusOpen, StatusClosing, StatusClosed, StatusActive,
uv_status_string, check_open, wait_connected,
UV_EINVAL, UV_ENOMEM, UV_ENOBUFS, UV_EAGAIN, UV_ECONNABORTED, UV_EADDRINUSE, UV_EACCES, UV_EADDRNOTAVAIL,
Expand Down Expand Up @@ -229,7 +229,7 @@ function bind(sock::Union{TCPServer, UDPSocket}, host::IPAddr, port::Integer; ip
if err < 0
if err != UV_EADDRINUSE && err != UV_EACCES && err != UV_EADDRNOTAVAIL
#TODO: this codepath is not currently tested
throw(UVError("bind", err))
throw(_UVError("bind", err))
else
return false
end
Expand Down Expand Up @@ -306,7 +306,7 @@ function uv_recvcb(handle::Ptr{Cvoid}, nread::Cssize_t, buf::Ptr{Cvoid}, addr::P
sock = @handle_as handle UDPSocket
if nread < 0
Libc.free(buf_addr)
notify_error(sock.recvnotify, UVError("recv", nread))
notify_error(sock.recvnotify, _UVError("recv", nread))
elseif flags & UV_UDP_PARTIAL > 0
Libc.free(buf_addr)
notify_error(sock.recvnotify, "Partial message received")
Expand Down Expand Up @@ -359,7 +359,7 @@ end
function uv_sendcb(handle::Ptr{Cvoid}, status::Cint)
sock = @handle_as handle UDPSocket
if status < 0
notify_error(sock.sendnotify, UVError("UDP send failed", status))
notify_error(sock.sendnotify, _UVError("UDP send failed", status))
end
notify(sock.sendnotify)
Libc.free(handle)
Expand All @@ -378,7 +378,7 @@ function uv_connectcb(conn::Ptr{Cvoid}, status::Cint)
notify(sock.connectnotify)
else
ccall(:jl_forceclose_uv, Cvoid, (Ptr{Cvoid},), hand)
err = UVError("connect", status)
err = _UVError("connect", status)
notify_error(sock.connectnotify, err)
end
Libc.free(conn)
Expand Down Expand Up @@ -497,8 +497,7 @@ function uv_connectioncb(stream::Ptr{Cvoid}, status::Cint)
if status >= 0
notify(sock.connectnotify)
else
err = UVError("connection", status)
notify_error(sock.connectnotify, err)
notify_error(sock.connectnotify, _UVError("connection", status))
end
nothing
end
Expand Down
Loading