From d031df211ef9ac269f328b93ed8e0aa196c03c83 Mon Sep 17 00:00:00 2001 From: Jan Weidner Date: Sat, 4 Nov 2017 15:25:26 +0100 Subject: [PATCH] Improve some error messages --- src/ArgCheck.jl | 8 +++++++- test/runtests.jl | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ArgCheck.jl b/src/ArgCheck.jl index 624a920..daa602d 100644 --- a/src/ArgCheck.jl +++ b/src/ArgCheck.jl @@ -130,7 +130,7 @@ 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) @@ -138,6 +138,12 @@ function fancy_error_message(code, exprs, values) 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 diff --git a/test/runtests.jl b/test/runtests.jl index ad44f31..5424e47 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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