Skip to content

In Julia 1.5 use custom hints to replace debug mode? #144

Open
@oxinabox

Description

@oxinabox

Right now we use debug mode (#136) with the special error type for addition of composites to primals failing, to give instructions on how to overload things to fix this.
But in julia 1.5 there is special functionality for adding hints for how to resolve errors build in by some magic:
JuliaLang/julia#35094

struct PrimalAdditionFailedException{P} <: Exception
primal::P
differential::Composite{P}
original::Exception
end
function Base.showerror(io::IO, err::PrimalAdditionFailedException{P}) where {P}
println(io, "Could not construct $P after addition.")
println(io, "This probably means no default constructor is defined.")
println(io, "Either define a default constructor")
printstyled(io, "$P(", join(propertynames(err.differential), ", "), ")", color=:blue)
println(io, "\nor overload")
printstyled(io,
"ChainRulesCore.construct(::Type{$P}, ::$(typeof(err.differential)))";
color=:blue
)
println(io, "\nor overload")
printstyled(io, "Base.:+(::$P, ::$(typeof(err.differential)))"; color=:blue)
println(io, "\nOriginal Exception:")
printstyled(io, err.original; color=:yellow)
println(io)
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions