Skip to content

Commit

Permalink
Avoid invalid use of SystemError
Browse files Browse the repository at this point in the history
Creating a partial `SystemError` struct will result in an
`UndefRefError` when attempting to display the exception:

```julia
julia> throw(SystemError("demo"))
ERROR: SYSTEM: show(lasterr) caused an error
UndefRefError()
```
  • Loading branch information
omus committed Sep 7, 2017
1 parent b8a8cbd commit fc5f145
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/local.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function localzone()
end
end

throw(SystemError("unable to locate tzfile: $name"))
error("unable to locate tzfile: $name")
end
end

Expand Down
19 changes: 15 additions & 4 deletions test/local.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,29 @@ if is_linux()
@test localzone() == utc
end

# Use system installed files
# Attempt to use system installed time zone files. On some minimal systems no time zone
# information will be available.
@test_throws ArgumentError TimeZone("Etc/GMT-9")
gmt_minus_9 = FixedTimeZone("Etc/GMT-9", 9 * 3600)
withenv("TZ" => ":Etc/GMT-9") do
@test localzone() == gmt_minus_9
try
tz = localzone()
@test tz == gmt_minus_9
catch err
msg = sprint(showerror, err)
if isa(err, ErrorException) && msg == "unable to locate tzfile: Etc/GMT-9"
warn("Skipping test: missing system time zone information")
else
rethrow()
end
end
end

# Unable to locate time zone on system
withenv("TZ" => ":") do
@test_throws SystemError localzone()
@test_throws ErrorException localzone()
end
withenv("TZ" => ":Etc/Foo") do
@test_throws SystemError localzone()
@test_throws ErrorException localzone()
end
end

0 comments on commit fc5f145

Please sign in to comment.