Skip to content

Commit 3a07c58

Browse files
committed
Clarify missing-file error message for load
`load` depends on the file already existing; in case of error, don't conflate format with existence.
1 parent 8e6b433 commit 3a07c58

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/loadsave.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ trying to infer the format from `filename`.
4949
- `save(Stream(format"PNG",io), data...)` specifies the format directly, and bypasses inference.
5050
- `save(f, data...; options...)` passes keyword arguments on to the saver.
5151
""" ->
52-
save(s::@compat(Union{AbstractString,IO}), data...; options...) =
52+
save(s::@compat(Union{AbstractString,IO}), data...; options...) =
5353
save(query(s), data...; options...)
5454

5555
# Forced format
@@ -68,7 +68,10 @@ end
6868

6969
# Fallbacks
7070
function load{F}(q::Formatted{F}, args...; options...)
71-
unknown(q) && throw(UnknownFormat(q))
71+
if unknown(q)
72+
isfile(filename(q)) || open(filename(q)) # force systemerror
73+
throw(UnknownFormat(q))
74+
end
7275
libraries = applicable_loaders(q)
7376
failures = Any[]
7477
for library in libraries

test/loadsave.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,7 @@ context("Ambiguous extension") do
174174

175175
rm(fn)
176176
end
177+
178+
context("Absent file") do
179+
@fact_throws SystemError load("nonexistent.oops")
180+
end

0 commit comments

Comments
 (0)