JuliaLang / Pkg.jl

Pkg - Package manager for the Julia programming language
https://pkgdocs.julialang.org
Other
621 stars 260 forks source link

`ResolverError` coloring should be decided in `showerror`, not on construction #4006

Open danielwe opened 1 month ago

danielwe commented 1 month ago

A ResolverError has color hardcoded in the message if stderr supports color, as the message is formatted on construction using the following function:

https://github.com/JuliaLang/Pkg.jl/blob/8b2c0f32939042e5d77da05d2825de6ec56487e9/src/Resolve/graphtype.jl#L571-L576

This is unfortunate when the error message isn't actually printed to stderr, for example in Pluto:

image

Perhaps it would be better to store data rather than a preformatted message in the ResolverError object, and only format the message in the showerror(io, ::ResolverError) method, with or without color depending on io.

danielwe commented 1 month ago

The most straightforward solution here is perhaps to use 1.11's new StyledStrings stdlib