Mercurial > repos > public > sbplib_julia
changeset 1964:3fb5b03162ee feature/grids/manifolds
Implement an error hint for MethodError with Grids.jacobian
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 11 Feb 2025 15:46:29 +0100 |
parents | 624e19c20c19 |
children | 3694f11075c5 |
files | src/Grids/Grids.jl src/Grids/manifolds.jl |
diffstat | 2 files changed, 13 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Grids/Grids.jl Tue Feb 11 09:10:19 2025 +0100 +++ b/src/Grids/Grids.jl Tue Feb 11 15:46:29 2025 +0100 @@ -83,4 +83,17 @@ include("zero_dim_grid.jl") include("mapped_grid.jl") +function __init__() + if !isdefined(Base.Experimental, :register_error_hint) + return + end + + Base.Experimental.register_error_hint(MethodError) do io, exc, argtypes, kwargs + if exc.f == Grids.jacobian + print(io, "\nThis possibly means that a function used to define a coordinate mapping is missing a method for `Grids.jacobian`.\n") + print(io, "Provide one by for exmple implementing `Grids.jacobian(::$(typeof(exc.args[1])), x) = ...` or `Grids.jacobian(f, x) = ForwardDiff.jacobian(f,x)`") + end + end +end + end # module
--- a/src/Grids/manifolds.jl Tue Feb 11 09:10:19 2025 +0100 +++ b/src/Grids/manifolds.jl Tue Feb 11 15:46:29 2025 +0100 @@ -31,7 +31,6 @@ which will both allow calling `jacobian(c,ξ)`. """ jacobian(c::Chart, ξ) = jacobian(c.mapping, ξ) -# TBD: Can we register a error hint for when jacobian is called with a function that doesn't have a registered jacobian? boundary_identifiers(c::Chart) = boundary_identifiers(parameterspace(c))