diff --git a/src/mcmc/hmc.jl b/src/mcmc/hmc.jl index d80502f7e..91bc7f572 100644 --- a/src/mcmc/hmc.jl +++ b/src/mcmc/hmc.jl @@ -170,7 +170,7 @@ function find_initial_params( # if we failed to find valid initial parameters, error return error( - "failed to find valid initial parameters in $(max_attempts) tries. This may indicate an error with the model or AD backend; please open an issue at https://github.com/TuringLang/Turing.jl/issues", + "failed to find valid initial parameters in $(max_attempts) tries. See https://turinglang.org/docs/uri/initial-parameters for common causes and solutions. If the issue persists, please open an issue at https://github.com/TuringLang/Turing.jl/issues", ) end diff --git a/test/mcmc/hmc.jl b/test/mcmc/hmc.jl index 839dffbbe..428c193ca 100644 --- a/test/mcmc/hmc.jl +++ b/test/mcmc/hmc.jl @@ -259,6 +259,20 @@ using Turing @test Turing.Inference.getstepsize(spl, hmc_state) isa Float64 end end + + @testset "improved error message for initialization failures" begin + # Model that always fails to initialize + @model function failing_model() + x ~ Normal() + @addlogprob! -Inf + end + + # Test that error message includes troubleshooting link + @test_throws ErrorException sample(failing_model(), NUTS(), 10; progress=false) + @test_throws "https://turinglang.org/docs/uri/initial-parameters" sample( + failing_model(), NUTS(), 10; progress=false + ) + end end end