JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.88k stars 5.49k forks source link

FR: allow MIME type for `showerror` #55987

Open fonsp opened 1 month ago

fonsp commented 1 month ago

Currently, showerror can be implemented by package developers as:

function Base.showerror(io::IO, err::MyErrorType)
    write(io, "...")
end

My request is that we document a new pattern of defining an additional show method with a MIME type, similar to Base.show:

function Base.showerror(io::IO, ::MIME"text/html", err::MyErrorType)
    write(io, "...")
end

The HTML mime type is my motivating use case. This would allow package developers to define richer error messages for notebooks. You could use headers (text size), hyperlinks, formatted code snippets, images with diagrams, collapsable sections with more debugging info, and more.

For REPL users, nothing would change.

fonsp commented 1 month ago

I'm also open to alternative suggestions that would achieve the same goal :)