From 1d4f6c78531e533d93818b21f9429598ce3606cd Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Thu, 25 Jan 2024 11:44:54 -0600 Subject: [PATCH] Add check in error hint (#199) MethodErrors can be generated for objects for which `nameof` has no method. Also updates to Aqua 0.8, and adds [compat]. We didn't have a [compat] before so the new release of Aqua broke our tests. --- Project.toml | 16 ++++++++++++++-- src/ImageCore.jl | 3 ++- test/functions.jl | 12 ++++++++++-- test/runtests.jl | 3 +-- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Project.toml b/Project.toml index 5aa9fba..42dc7e6 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ImageCore" uuid = "a09fc81d-aa75-5fe9-8630-4744c3626534" -version = "0.10.1" +version = "0.10.2" [deps] ColorVectorSpace = "c3611d14-8923-5661-9e6a-0046d554d3a4" @@ -14,15 +14,26 @@ PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" [compat] +Aqua = "0.8" +BlockArrays = "0.16" ColorVectorSpace = "0.10" Colors = "0.12" +Documenter = "1" +FFTW = "1" FixedPointNumbers = "0.8" +ImageIO = "0.6" +ImageInTerminal = "0.5" +Logging = "1" MappedArrays = "0.2, 0.3, 0.4" MosaicViews = "0.3.3" OffsetArrays = "0.8, 0.9, 0.10, 0.11, 1.0.1" PaddedViews = "0.5.8" PrecompileTools = "1" +Random = "1" Reexport = "0.2, 1.0" +ReferenceTests = "0.10" +Statistics = "1" +Test = "1" julia = "1.6" [extras] @@ -32,10 +43,11 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19" ImageInTerminal = "d8c32880-2388-543b-8c61-d9f865259254" +Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Aqua", "BlockArrays", "Documenter", "FFTW", "ImageIO", "ImageInTerminal", "Random", "ReferenceTests", "Statistics", "Test"] +test = ["Aqua", "BlockArrays", "Documenter", "FFTW", "ImageIO", "ImageInTerminal", "Logging", "Random", "ReferenceTests", "Statistics", "Test"] diff --git a/src/ImageCore.jl b/src/ImageCore.jl index b7f7d02..ef8cd3a 100644 --- a/src/ImageCore.jl +++ b/src/ImageCore.jl @@ -171,7 +171,8 @@ end function __init__() Base.Experimental.register_error_hint(MethodError) do io, exc, argtypes, kwargs - if nameof(exc.f) ∈ (:fft, :rfft, :plan_fft, :plan_rfft, :realfloat) && argtypes[1] <: AbstractArray{<:Colorant} + f = exc.f + if isa(f, Function) && nameof(f) ∈ (:fft, :rfft, :plan_fft, :plan_rfft, :realfloat) && argtypes[1] <: AbstractArray{<:Colorant} throw_ffterror(io, exc.f, exc.args...) end end diff --git a/test/functions.jl b/test/functions.jl index 837ccdf..2deef4d 100644 --- a/test/functions.jl +++ b/test/functions.jl @@ -1,4 +1,7 @@ +using ImageCore using FFTW +using Logging +using Test @testset "functions" begin ag = rand(Gray{Float32}, 4, 5) @@ -8,14 +11,19 @@ using FFTW (fft, (ac,)), (fft, (ac, 1:2)), (plan_fft, (ac,)), (rfft, (ac,)), (rfft, (ac, 1:2)), (plan_rfft, (ac,))) dims_str = eltype(args[1])<:Gray ? "1:2" : "2:3" - ret = @test_throws "channelview, and likely $dims_str" f(args...) + @test_throws "channelview, and likely $dims_str" f(args...) end for (a, dims) in ((ag, 1:2), (ac, 2:3)) @test ifft(fft(channelview(a), dims), dims) ≈ channelview(a) ret = @test_throws "channelview, and likely $dims" rfft(a) @test irfft(rfft(channelview(a), dims), 4, dims) ≈ channelview(a) end - + # Ensure that the hint doesn't error + @test_logs min_level=Logging.Warn try + [3](1, 2) + catch err + showerror(devnull, err) + end a = [RGB(1,0,0), RGB(0,1,0), RGB(0,0,1)] @test a' == [RGB(1,0,0) RGB(0,1,0) RGB(0,0,1)] diff --git a/test/runtests.jl b/test/runtests.jl index 4ab417d..d00b7ca 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -13,8 +13,7 @@ using Aqua, Documenter # for meta quality checks deps_compat=true, stale_deps=true, # FIXME? re-enable the `piracy` test - piracy=false, # currently just `float` and `paddedviews` - project_toml_formatting=true, + piracies=false, # currently just `float` and `paddedviews` unbound_args=true, ) DocMeta.setdocmeta!(ImageCore, :DocTestSetup, :(using ImageCore); recursive=true)