Skip to content

Commit c38ef5a

Browse files
authored
Merge pull request #79 from JuliaIO/teh/stackoverflow
Fix stack overflow when load/save are missing
2 parents 0108823 + eb08348 commit c38ef5a

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/error_handling.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ immutable LoaderError <: Exception
88
msg::Compat.UTF8String
99
end
1010
Base.showerror(io::IO, e::LoaderError) = println(io, e.library, " load error: ",
11-
msg, "\n Will try next loader.")
11+
e.msg, "\n Will try next loader.")
1212

1313
"""
1414
`WriterError` should be thrown when writer library code fails, and other libraries should
@@ -21,7 +21,7 @@ immutable WriterError <: Exception
2121
end
2222
Base.showerror(io::IO, e::WriterError) = println(
2323
io, e.library, " writer error: ",
24-
msg, "\n Will try next writer."
24+
e.msg, "\n Will try next writer."
2525
)
2626

2727
"""

src/loadsave.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ function load{F}(q::Formatted{F}, args...; options...)
7979
for library in libraries
8080
try
8181
Library = checked_import(library)
82+
if !isdefined(Library, :load) || Library.load == FileIO.load
83+
throw(LoaderError(string(library), "load not defined"))
84+
end
8285
return Library.load(q, args...; options...)
8386
catch e
8487
handle_current_error(e, library, library == last(libraries))
@@ -94,6 +97,9 @@ function save{F}(q::Formatted{F}, data...; options...)
9497
for library in libraries
9598
try
9699
Library = checked_import(library)
100+
if !isdefined(Library, :save) || Library.save == FileIO.save
101+
throw(WriterError(string(library), "save not defined"))
102+
end
97103
return Library.save(q, data...; options...)
98104
catch e
99105
handle_current_error(e, library, library == last(libraries))

test/error_handling.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,18 @@ context("Not installed") do
2626
eval(Base, :(is_interactive = false)) # for interactive error handling
2727

2828
end
29+
30+
31+
# Missing load/save functions
32+
module BrokenIO
33+
using FileIO
34+
end
35+
add_format(format"BROKEN", (), ".brok", [:BrokenIO])
36+
37+
context("Absent implementation") do
38+
stderr_copy = STDERR
39+
rserr, wrerr = redirect_stderr()
40+
@fact_throws FileIO.LoaderError load(Stream(format"BROKEN", STDIN))
41+
@fact_throws FileIO.WriterError save(Stream(format"BROKEN", STDOUT))
42+
redirect_stderr(stderr_copy)
43+
end

0 commit comments

Comments
 (0)