Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering: Provide some way to show multiple nested errors (or display related as nested) #416

Closed
elkowar opened this issue Dec 22, 2024 · 3 comments · Fixed by #417
Closed

Comments

@elkowar
Copy link
Contributor

elkowar commented Dec 22, 2024

Currently, the related errors of a given report will show just one after another, without any clear indication of them belonging tightly to the outer error.

I.e., in my project, right now I have errors like these:
image

Which are supposed to express that the two related errors are actually part of the outer error -- clearly not quite the intended use for related.

I can get closer to a more intuitive visualization by storing the related errors in a simple struct ErrList(#[related] Vec<Report>):

image

However, this now requires me to have another error message be displayed, which often doesn't add any semantic value, and takes up a lot of space.

For cases like these, where I really want to show several siblings as nested within one outer error, I'd optimally want to have them be displayed roughly like this:

image

My proposal here would be to add a variant of "related" errors that explicitly declare them as nested, i.e.:

#[derive(Diagnostic, Error, Debug)]
#[error("{message}")]
#[diagnostic]
struct ManyErrors {
  message: String
  #[related(nested)]
  errors: Vec<Report>
}
@zkat
Copy link
Owner

zkat commented Dec 22, 2024

This is a reasonable proposal! I’d be happy to take this change :)

@elkowar
Copy link
Contributor Author

elkowar commented Dec 22, 2024

Nice! I'd love to take a stab at this, but I'm a bit unsure on how to approach an implementation here:

If the idea is to actually have this as a property of the related attribute, then I don't know how to express that within the current structure of the Diagnostic trait.
Alternatively, I could just add a separate nested field to the Diagnostic trait, which would potentially feel cleaner, but is also a much larger change to the API.
A third, minimally invasive, approach would be to just make the way related errors are shown a global setting in the GraphicalReportHandler.

What do you think, @zkat? Or is there something else I'm missing?

@zkat
Copy link
Owner

zkat commented Dec 22, 2024

Probably a configuration in the GraphicalReportHandler is probably best, esp since this is all about controlling how things look, rather than some fundamental property about the relationship between diagnostics

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants