Skip to content

Commit

Permalink
Add check in error hint
Browse files Browse the repository at this point in the history
MethodErrors can be generated for objects for which `nameof`
has no method.
  • Loading branch information
timholy committed Jan 25, 2024
1 parent 2ed7df8 commit 190762c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
6 changes: 4 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -17,6 +17,7 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
ColorVectorSpace = "0.10"
Colors = "0.12"
FixedPointNumbers = "0.8"
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"
Expand All @@ -32,10 +33,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"]
3 changes: 2 additions & 1 deletion src/ImageCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions test/functions.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using ImageCore
using FFTW
using Logging
using Test

@testset "functions" begin
ag = rand(Gray{Float32}, 4, 5)
Expand All @@ -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)]
Expand Down

0 comments on commit 190762c

Please sign in to comment.