Skip to content

Commit 84fa23b

Browse files
committed
fix #7841, rename UVError to IOError
1 parent 937bd74 commit 84fa23b

21 files changed

+71
-67
lines changed

base/deprecated.jl

+2
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ end
395395
@deprecate readstring(filename::AbstractString) read(filename, String)
396396
@deprecate readstring(cmd::AbstractCmd) read(cmd, String)
397397

398+
@deprecate_binding UVError IOError false
399+
398400
# issue #11310
399401
# remove "parametric method syntax" deprecation in julia-syntax.scm
400402

base/error.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ retry(f, delays=fill(5.0, 3))
191191
retry(f, delays=rand(5:10, 2))
192192
retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000))
193193
retry(http_get, check=(s,e)->e.status == "503")(url)
194-
retry(read, check=(s,e)->isa(e, UVError))(io, 128; all=false)
194+
retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false)
195195
```
196196
"""
197197
function retry(f::Function; delays=ExponentialBackOff(), check=nothing)

base/event.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ mutable struct AsyncCondition
295295
#TODO: this codepath is currently not tested
296296
Libc.free(this.handle)
297297
this.handle = C_NULL
298-
throw(UVError("uv_async_init", err))
298+
throw(_UVError("uv_async_init", err))
299299
end
300300
return this
301301
end
@@ -353,7 +353,7 @@ mutable struct Timer
353353
#TODO: this codepath is currently not tested
354354
Libc.free(this.handle)
355355
this.handle = C_NULL
356-
throw(UVError("uv_timer_init", err))
356+
throw(_UVError("uv_timer_init", err))
357357
end
358358

359359
associate_julia_struct(this.handle, this)

base/file.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ function rm(path::AbstractString; force::Bool=false, recursive::Bool=false)
252252
end
253253
unlink(path)
254254
catch err
255-
if force && isa(err, UVError) && err.code==Base.UV_ENOENT
255+
if force && isa(err, IOError) && err.code==Base.UV_ENOENT
256256
return
257257
end
258258
rethrow()

base/filesystem.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export File,
3939
S_IROTH, S_IWOTH, S_IXOTH, S_IRWXO
4040

4141
import .Base:
42-
UVError, _sizeof_uv_fs, check_open, close, eof, eventloop, fd, isopen,
42+
IOError, _UVError, _sizeof_uv_fs, check_open, close, eof, eventloop, fd, isopen,
4343
bytesavailable, position, read, read!, readavailable, seek, seekend, show,
4444
skip, stat, unsafe_read, unsafe_write, write, transcode, uv_error,
4545
rawhandle, OS_HANDLE, INVALID_OS_HANDLE

base/initdefs.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ end
100100
function current_project()
101101
dir = try pwd()
102102
catch err
103-
err isa UVError || rethrow(err)
103+
err isa IOError || rethrow(err)
104104
return nothing
105105
end
106106
return current_project(dir)

base/libuv.jl

+9-7
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,22 @@ end
6565

6666
## Libuv error handling ##
6767

68-
struct UVError <: Exception
69-
prefix::AbstractString
68+
struct IOError <: Exception
69+
msg::AbstractString
7070
code::Int32
71-
UVError(p::AbstractString, code::Integer) = new(p,code)
71+
IOError(p::AbstractString, code::Integer) = new(p, code)
72+
end
73+
74+
function _UVError(pfx::AbstractString, code::Integer)
75+
code = Int32(code)
76+
IOError(string(pfx, ": ", struverror(code), " (", uverrorname(code), ")"), code)
7277
end
7378

7479
struverror(err::Int32) = unsafe_string(ccall(:uv_strerror,Cstring,(Int32,),err))
75-
struverror(err::UVError) = struverror(err.code)
7680
uverrorname(err::Int32) = unsafe_string(ccall(:uv_err_name,Cstring,(Int32,),err))
77-
uverrorname(err::UVError) = uverrorname(err.code)
7881

7982
uv_error(prefix::Symbol, c::Integer) = uv_error(string(prefix),c)
80-
uv_error(prefix::AbstractString, c::Integer) = c < 0 ? throw(UVError(prefix,c)) : nothing
81-
show(io::IO, e::UVError) = print(io, e.prefix*": "*struverror(e)*" ("*uverrorname(e)*")")
83+
uv_error(prefix::AbstractString, c::Integer) = c < 0 ? throw(_UVError(prefix,c)) : nothing
8284

8385
## event loop ##
8486

base/process.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ function _jl_spawn(file, argv, cmd::Cmd, stdio)
367367
uv_jl_return_spawn::Ptr{Cvoid})
368368
if error != 0
369369
ccall(:jl_forceclose_uv, Cvoid, (Ptr{Cvoid},), proc)
370-
throw(UVError("could not spawn " * string(cmd), error))
370+
throw(_UVError("could not spawn " * string(cmd), error))
371371
end
372372
return proc
373373
end
@@ -687,7 +687,7 @@ function test_success(proc::Process)
687687
@assert process_exited(proc)
688688
if proc.exitcode < 0
689689
#TODO: this codepath is not currently tested
690-
throw(UVError("could not start process $(string(proc.cmd))", proc.exitcode))
690+
throw(_UVError("could not start process $(string(proc.cmd))", proc.exitcode))
691691
end
692692
proc.exitcode == 0 && (proc.termsignal == 0 || proc.termsignal == SIGPIPE)
693693
end
@@ -743,7 +743,7 @@ function kill(p::Process, signum::Integer)
743743
@assert p.handle != C_NULL
744744
err = ccall(:uv_process_kill, Int32, (Ptr{Cvoid}, Int32), p.handle, signum)
745745
if err != 0 && err != UV_ESRCH
746-
throw(UVError("kill", err))
746+
throw(_UVError("kill", err))
747747
end
748748
end
749749
end

base/stat.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ macro stat_call(sym, arg1type, arg)
6565
return quote
6666
stat_buf = zeros(UInt8, ccall(:jl_sizeof_stat, Int32, ()))
6767
r = ccall($(Expr(:quote, sym)), Int32, ($(esc(arg1type)), Ptr{UInt8}), $(esc(arg)), stat_buf)
68-
r == 0 || r == Base.UV_ENOENT || r == Base.UV_ENOTDIR || throw(UVError("stat", r))
68+
r == 0 || r == Base.UV_ENOENT || r == Base.UV_ENOTDIR || throw(_UVError("stat", r))
6969
st = StatStruct(stat_buf)
7070
if ispath(st) != (r == 0)
7171
error("stat returned zero type for a valid path")

base/stream.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ function uv_readcb(handle::Ptr{Cvoid}, nread::Cssize_t, buf::Ptr{Cvoid})
490490
# This is a fatal connection error. Shutdown requests as per the usual
491491
# close function won't work and libuv will fail with an assertion failure
492492
ccall(:jl_forceclose_uv, Cvoid, (Ptr{Cvoid},), stream)
493-
notify_error(stream.readnotify, UVError("read", nread))
493+
notify_error(stream.readnotify, _UVError("read", nread))
494494
end
495495
else
496496
notify_filled(stream.buffer, nread)
@@ -882,7 +882,7 @@ function uv_writecb_task(req::Ptr{Cvoid}, status::Cint)
882882
uv_req_set_data(req, C_NULL) # let the Task know we got the writecb
883883
t = unsafe_pointer_to_objref(d)::Task
884884
if status < 0
885-
err = UVError("write", status)
885+
err = _UVError("write", status)
886886
schedule(t, err, error=true)
887887
else
888888
schedule(t)

stdlib/FileWatching/src/FileWatching.jl

+13-13
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export
2020
PollingFileWatcher,
2121
FDWatcher
2222

23-
import Base: @handle_as, wait, close, eventloop, notify_error, stream_wait,
24-
_sizeof_uv_poll, _sizeof_uv_fs_poll, _sizeof_uv_fs_event, _uv_hook_close, uv_error, UVError,
23+
import Base: @handle_as, wait, close, eventloop, notify_error, stream_wait, IOError,
24+
_sizeof_uv_poll, _sizeof_uv_fs_poll, _sizeof_uv_fs_event, _uv_hook_close, uv_error, _UVError,
2525
associate_julia_struct, disassociate_julia_struct, isreadable, iswritable, |
2626
import Base.Filesystem.StatStruct
2727
if Sys.iswindows()
@@ -85,7 +85,7 @@ mutable struct FileMonitor
8585
err = ccall(:uv_fs_event_init, Cint, (Ptr{Cvoid}, Ptr{Cvoid}), eventloop(), handle)
8686
if err != 0
8787
Libc.free(handle)
88-
throw(UVError("FileMonitor", err))
88+
throw(_UVError("FileMonitor", err))
8989
end
9090
finalizer(uvfinalize, this)
9191
return this
@@ -95,7 +95,7 @@ end
9595

9696
mutable struct FolderMonitor
9797
handle::Ptr{Cvoid}
98-
notify::Channel{Any} # eltype = Union{Pair{String, FileEvent}, UVError}
98+
notify::Channel{Any} # eltype = Union{Pair{String, FileEvent}, IOError}
9999
open::Bool
100100
FolderMonitor(folder::AbstractString) = FolderMonitor(String(folder))
101101
function FolderMonitor(folder::String)
@@ -105,7 +105,7 @@ mutable struct FolderMonitor
105105
err = ccall(:uv_fs_event_init, Cint, (Ptr{Cvoid}, Ptr{Cvoid}), eventloop(), handle)
106106
if err != 0
107107
Libc.free(handle)
108-
throw(UVError("FolderMonitor", err))
108+
throw(_UVError("FolderMonitor", err))
109109
end
110110
this.open = true
111111
finalizer(uvfinalize, this)
@@ -132,7 +132,7 @@ mutable struct PollingFileWatcher
132132
err = ccall(:uv_fs_poll_init, Int32, (Ptr{Cvoid}, Ptr{Cvoid}), eventloop(), handle)
133133
if err != 0
134134
Libc.free(handle)
135-
throw(UVError("PollingFileWatcher", err))
135+
throw(_UVError("PollingFileWatcher", err))
136136
end
137137
finalizer(uvfinalize, this)
138138
return this
@@ -180,7 +180,7 @@ mutable struct _FDWatcher
180180
err = ccall(:uv_poll_init, Int32, (Ptr{Cvoid}, Ptr{Cvoid}, RawFD), eventloop(), handle, fd)
181181
if err != 0
182182
Libc.free(handle)
183-
throw(UVError("FDWatcher", err))
183+
throw(_UVError("FDWatcher", err))
184184
end
185185
finalizer(uvfinalize, this)
186186
FDWatchers[fdnum] = this
@@ -229,7 +229,7 @@ mutable struct _FDWatcher
229229
eventloop(), handle, fd)
230230
if err != 0
231231
Libc.free(handle)
232-
throw(UVError("FDWatcher", err))
232+
throw(_UVError("FDWatcher", err))
233233
end
234234
finalizer(uvfinalize, this)
235235
return this
@@ -314,7 +314,7 @@ end
314314
function uv_fseventscb_file(handle::Ptr{Cvoid}, filename::Ptr, events::Int32, status::Int32)
315315
t = @handle_as handle FileMonitor
316316
if status != 0
317-
notify_error(t.notify, UVError("FileMonitor", status))
317+
notify_error(t.notify, _UVError("FileMonitor", status))
318318
else
319319
t.events |= events
320320
notify(t.notify, FileEvent(events))
@@ -325,7 +325,7 @@ end
325325
function uv_fseventscb_folder(handle::Ptr{Cvoid}, filename::Ptr, events::Int32, status::Int32)
326326
t = @handle_as handle FolderMonitor
327327
if status != 0
328-
put!(t.notify, UVError("FolderMonitor", status))
328+
put!(t.notify, _UVError("FolderMonitor", status))
329329
else
330330
fname = (filename == C_NULL) ? "" : unsafe_string(convert(Cstring, filename))
331331
put!(t.notify, fname => FileEvent(events))
@@ -336,7 +336,7 @@ end
336336
function uv_pollcb(handle::Ptr{Cvoid}, status::Int32, events::Int32)
337337
t = @handle_as handle _FDWatcher
338338
if status != 0
339-
notify_error(t.notify, UVError("FDWatcher", status))
339+
notify_error(t.notify, _UVError("FDWatcher", status))
340340
else
341341
t.events |= events
342342
if t.active[1] || t.active[2]
@@ -491,7 +491,7 @@ function wait(pfw::PollingFileWatcher)
491491
if pfw.handle == C_NULL
492492
return prevstat, EOFError()
493493
elseif pfw.curr_error != 0
494-
return prevstat, UVError("PollingFileWatcher", pfw.curr_error)
494+
return prevstat, _UVError("PollingFileWatcher", pfw.curr_error)
495495
else
496496
return prevstat, pfw.curr_stat
497497
end
@@ -685,7 +685,7 @@ function poll_file(s::AbstractString, interval_seconds::Real=5.007, timeout_s::R
685685
@async (sleep(timeout_s); close(pfw))
686686
end
687687
statdiff = wait(pfw)
688-
if isa(statdiff[2], UVError)
688+
if isa(statdiff[2], IOError)
689689
# file didn't initially exist, continue watching for it to be created (or the error to change)
690690
statdiff = wait(pfw)
691691
end

stdlib/FileWatching/test/runtests.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,9 @@ let changes = []
421421
@test all(x -> (isa(x, Pair) && x[1] == F_PATH && (x[2].changed x[2].renamed)), changes) || changes
422422
end
423423

424-
@test_throws(Base.UVError("FileMonitor (start)", Base.UV_ENOENT),
424+
@test_throws(Base._UVError("FileMonitor (start)", Base.UV_ENOENT),
425425
watch_file("____nonexistent_file", 10))
426-
@test_throws(Base.UVError("FolderMonitor (start)", Base.UV_ENOENT),
426+
@test_throws(Base._UVError("FolderMonitor (start)", Base.UV_ENOENT),
427427
watch_folder("____nonexistent_file", 10))
428428
@test(@elapsed(
429429
@test(poll_file("____nonexistent_file", 1, 3.1) ===

stdlib/Mmap/test/runtests.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ close(s); finalize(m); m=nothing; GC.gc()
5959

6060
s = open(file, "r")
6161
close(s)
62-
@test_throws Base.UVError Mmap.mmap(s) # closed IOStream
62+
@test_throws Base.IOError Mmap.mmap(s) # closed IOStream
6363
@test_throws ArgumentError Mmap.mmap(s,Vector{UInt8},12,0) # closed IOStream
6464
@test_throws SystemError Mmap.mmap("")
6565

stdlib/Sockets/src/PipeServer.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function bind(server::PipeServer, name::AbstractString)
5252
if err != 0
5353
if err != UV_EADDRINUSE && err != UV_EACCES
5454
#TODO: this codepath is currently not tested
55-
throw(UVError("bind",err))
55+
throw(_UVError("bind",err))
5656
else
5757
return false
5858
end

stdlib/Sockets/src/Sockets.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export
2727
import Base: isless, show, print, parse, bind, convert, isreadable, iswritable, alloc_buf_hook, _uv_hook_close
2828

2929
using Base: LibuvStream, LibuvServer, PipeEndpoint, @handle_as, uv_error, associate_julia_struct, uvfinalize,
30-
notify_error, stream_wait, uv_req_data, uv_req_set_data, preserve_handle, unpreserve_handle, UVError,
30+
notify_error, stream_wait, uv_req_data, uv_req_set_data, preserve_handle, unpreserve_handle, _UVError, IOError,
3131
eventloop, StatusUninit, StatusInit, StatusConnecting, StatusOpen, StatusClosing, StatusClosed, StatusActive,
3232
uv_status_string, check_open, wait_connected,
3333
UV_EINVAL, UV_ENOMEM, UV_ENOBUFS, UV_EAGAIN, UV_ECONNABORTED, UV_EADDRINUSE, UV_EACCES, UV_EADDRNOTAVAIL,

stdlib/Sockets/src/addrinfo.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function uv_getaddrinfocb(req::Ptr{Cvoid}, status::Cint, addrinfo::Ptr{Cvoid})
1616
t = unsafe_pointer_to_objref(data)::Task
1717
uv_req_set_data(req, C_NULL)
1818
if status != 0 || addrinfo == C_NULL
19-
schedule(t, UVError("getaddrinfocb", status))
19+
schedule(t, _UVError("getaddrinfocb", status))
2020
else
2121
freeaddrinfo = addrinfo
2222
addrs = IPAddr[]
@@ -88,7 +88,7 @@ function getalladdrinfo(host::String)
8888
end
8989
unpreserve_handle(ct)
9090
end
91-
if isa(r, UVError)
91+
if isa(r, IOError)
9292
code = r.code
9393
if code in (UV_EAI_ADDRFAMILY, UV_EAI_AGAIN, UV_EAI_BADFLAGS,
9494
UV_EAI_BADHINTS, UV_EAI_CANCELED, UV_EAI_FAIL,
@@ -99,7 +99,7 @@ function getalladdrinfo(host::String)
9999
elseif code == UV_EAI_MEMORY
100100
throw(OutOfMemoryError())
101101
else
102-
throw(UVError("getaddrinfo", code))
102+
throw(_UVError("getaddrinfo", code))
103103
end
104104
end
105105
return r::Vector{IPAddr}
@@ -130,7 +130,7 @@ function uv_getnameinfocb(req::Ptr{Cvoid}, status::Cint, hostname::Cstring, serv
130130
t = unsafe_pointer_to_objref(data)::Task
131131
uv_req_set_data(req, C_NULL)
132132
if status != 0
133-
schedule(t, UVError("getnameinfocb", status))
133+
schedule(t, _UVError("getnameinfocb", status))
134134
else
135135
schedule(t, unsafe_string(hostname))
136136
end
@@ -194,7 +194,7 @@ function getnameinfo(address::Union{IPv4, IPv6})
194194
end
195195
unpreserve_handle(ct)
196196
end
197-
if isa(r, UVError)
197+
if isa(r, IOError)
198198
code = r.code
199199
if code in (UV_EAI_ADDRFAMILY, UV_EAI_AGAIN, UV_EAI_BADFLAGS,
200200
UV_EAI_BADHINTS, UV_EAI_CANCELED, UV_EAI_FAIL,
@@ -205,7 +205,7 @@ function getnameinfo(address::Union{IPv4, IPv6})
205205
elseif code == UV_EAI_MEMORY
206206
throw(OutOfMemoryError())
207207
else
208-
throw(UVError("getnameinfo", code))
208+
throw(_UVError("getnameinfo", code))
209209
end
210210
end
211211
return r::String

0 commit comments

Comments
 (0)