Skip to content

Commit

Permalink
Merge pull request #431 from ReactiveBayes/method-error-factornode
Browse files Browse the repository at this point in the history
Add a hint for the undefined factor nodes
  • Loading branch information
bvdmitri authored Nov 27, 2024
2 parents 7f9e27c + c68f74c commit 1c07868
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/ReactiveMP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ function __init__()
@require Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" include("../ext/ReactiveMPZygoteExt/ReactiveMPZygoteExt.jl")
@require ExponentialFamilyProjection = "17f509fa-9a96-44ba-99b2-1c5f01f0931b" include("../ext/ReactiveMPProjectionExt/ReactiveMPProjectionExt.jl")
end

Base.Experimental.register_error_hint(MethodError) do io, exc, argtypes, kwargs
if exc.f == ReactiveMP.factornode && length(argtypes) >= 2 && argtypes[1] == ReactiveMP.UndefinedNodeFunctionalForm
errmsg = """
`$(argtypes[2])` has been used but the `ReactiveMP` backend does not support `$(argtypes[2])` as a factor node.
Please refer to the [factor nodes](https://reactivebayes.github.io/ReactiveMP.jl/stable/lib/nodes/) section of the documentation for more details.
"""
println(io, errmsg)
end
end
end

end
14 changes: 14 additions & 0 deletions test/nodes/nodes_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,17 @@ end
end
end
end

@testitem "`factornode` should throw an error if the functional form is not defined with the `@node` macro" begin
struct UnknownDistribution end

out = randomvar()
alpha = randomvar()
beta = randomvar()

interfaces = [(:out, out), (:alpha, alpha), (:beta, beta)]

@test_throws r"`.*UnknownDistribution.*` has been used but the `ReactiveMP` backend does not support `.*UnknownDistribution.*` as a factor node." factornode(
UnknownDistribution, interfaces, ((1, 2, 3),)
)
end

0 comments on commit 1c07868

Please sign in to comment.