Skip to content

Commit 85c526d

Browse files
committed
Improve error messaging
1 parent 28cdbbc commit 85c526d

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/scaling/scaling.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ end
55
ScaledInterpolation{T,ITPT,IT,GT,RT}(::Type{T}, N, itp::ITPT, ::Type{IT}, ::Type{GT}, ranges::RT) =
66
ScaledInterpolation{T,N,ITPT,IT,GT,RT}(itp, ranges)
77
function scale{T,N,IT,GT}(itp::AbstractInterpolation{T,N,IT,GT}, ranges::Range...)
8-
length(ranges) == N || error("Must scale $N-dimensional interpolation object with exactly $N ranges (you used $(length(ranges)))")
8+
length(ranges) == N || throw(ArgumentError("Must scale $N-dimensional interpolation object with exactly $N ranges (you used $(length(ranges)))"))
99
for d in 1:N
1010
if iextract(IT,d) != NoInterp
11-
length(ranges[d]) == size(itp,d) || error("The length of the range in dimension $d ($(length(ranges[d]))) did not equal the size of the interpolation object in that direction ($(size(itp,d)))")
11+
length(ranges[d]) == size(itp,d) || throw(ArgumentError("The length of the range in dimension $d ($(length(ranges[d]))) did not equal the size of the interpolation object in that direction ($(size(itp,d)))"))
1212
elseif ranges[d] != 1:size(itp,d)
13-
error("NoInterp dimension $d must be scaled with unit range 1:$(size(itp,d))")
13+
throw(ArgumentError("NoInterp dimension $d must be scaled with unit range 1:$(size(itp,d))"))
1414
end
1515
end
1616

@@ -42,7 +42,7 @@ gradient{T,N}(sitp::ScaledInterpolation{T,N}, xs...) = gradient!(Array(T,N), sit
4242
interp_indices = map(i -> interp_dimens[i] ? :(coordlookup(sitp.ranges[$i], xs[$i])) : :(xs[$i]), 1:N)
4343

4444
quote
45-
length(g) == N || error(string("g must be a vector of length ", N, " (was ", length(g), ")"))
45+
length(g) == N || throw(ArgumentError(string("g must be a vector of length ", N, " (was ", length(g), ")")))
4646
gradient!(g, sitp.itp, $(interp_indices...))
4747
for i in eachindex(g)
4848
g[i] = rescale_gradient(sitp.ranges[i], g[i])

test/scaling/nointerp.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@ end
2121

2222
# Test error messages for incorrect initialization
2323
function message_is(message)
24-
r -> r.err.msg == message || error("Incorrect error message: expected '$message' but was '$(r.msg)'")
24+
r -> r.err.msg == message || error("Incorrect error message: expected '$message' but was '$(r.err.msg)'")
2525
end
2626
Test.with_handler(message_is("Must scale 2-dimensional interpolation object with exactly 2 ranges (you used 1)")) do
2727
@test scale(itp, xs)
2828
end
2929
Test.with_handler(message_is("NoInterp dimension 2 must be scaled with unit range 1:3")) do
3030
@test scale(itp, xs, -1:1)
3131
end
32+
Test.with_handler(message_is("The length of the range in dimension 1 (8) did not equal the size of the interpolation object in that direction (11)")) do
33+
@test scale(itp, -pi:2pi/7:pi, 1:3)
34+
end
3235
Test.with_handler(message_is("Must index into 2-dimensional scaled interpolation object with exactly 2 indices (you used 1)")) do
3336
@test sitp[2.3]
3437
end
35-
3638
end

0 commit comments

Comments
 (0)