Skip to content

Commit

Permalink
Improve some error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jw3126 committed Nov 4, 2017
1 parent c891d07 commit d031df2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/ArgCheck.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,20 @@ build_error_with_fancy_message(code, variables, values, args...) = build_error(c
end

function fancy_error_message(code, exprs, values)
lines = ["$code must hold. Got"]
lines = String[]
foreach(exprs, values) do ex, val
sex = string(ex)
sval = string(val)
if sex != sval
push!(lines, "$sex => $sval")
end
end
firstline = if isempty(lines)
"$code must hold."
else
"$code must hold. Got"
end
unshift!(lines, firstline)
join(lines, '\n')
end

Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ end
@test contains(msg, "y")
@test contains(msg, "z")
@test contains(msg, "x")
@test contains(msg, "Got")
@test contains(msg, "fail_function")

err = @catch_exception_object @argcheck issorted([2,1])
@test !contains(err.msg, "Got")
end

@testset "keyword arguments" begin
Expand Down

0 comments on commit d031df2

Please sign in to comment.