Skip to content

Commit f73b630

Browse files
committed
Add hint for MethodErrors on LogDensityModel
1 parent e742318 commit f73b630

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/AbstractMCMC.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,19 @@ include("stepper.jl")
8888
include("transducer.jl")
8989
include("logdensityproblems.jl")
9090

91+
function __init__()
92+
if isdefined(Base.Experimental, :register_error_hint)
93+
Base.Experimental.register_error_hint(MethodError) do io, exc, argtypes, _
94+
if Base.parentmodule(exc.f) == LogDensityProblems &&
95+
any(a -> a <: LogDensityModel, argtypes)
96+
printstyled(
97+
io,
98+
"\nAbstractMCMC.LogDensityModel is a wrapper and does not itself implement the LogDensityProblems.jl interface. To use LogDensityProblems.jl methods, access the inner type with (e.g.) `logdensity(model.logdensity, params)` instead of `logdensity(model, params)`.";
99+
color=:cyan,
100+
)
101+
end
102+
end
103+
end
104+
end
105+
91106
end # module AbstractMCMC

0 commit comments

Comments
 (0)