Skip to content

Conversation

@walker84837
Copy link

@walker84837 walker84837 commented Oct 9, 2025

This PR enables converting Box<dyn Diagnostic> into MietteDiagnostic, so boxed errors can be turned into miette's structured diagnostic type without extra boilerplate. This matches miette's use of MietteDiagnostic as the standard runtime-built diagnostic, and fills a missing conversion path for trait-object errors. It's useful whenever errors are erased behind Box<dyn Diagnostic> and later need to be reported through miette (like in logging or serialization). Fixes #285.

@walker84837 walker84837 deleted the feat/from-boxed-diagnostic branch October 10, 2025 20:48
@walker84837 walker84837 restored the feat/from-boxed-diagnostic branch October 10, 2025 20:48
@walker84837 walker84837 reopened this Oct 10, 2025
@cgettys-microsoft
Copy link
Contributor

When would this be helpful? Just seeking to understand, given the lack of PR description (not my project, not my call what to merge).

@walker84837
Copy link
Author

Sorry for not providing a description earlier.

This PR adds an implementation of From<Box<dyn Diagnostic>> for MietteDiagnostic, which was requested in issue #285. This lets you convert a boxed dyn Diagnostic into a concrete MietteDiagnostic by pulling out the message, code, severity, help text, URL, and labels through the trait methods.

Off the top of my head, here are some reasons why you might want something like this:

  • When you have a Box<dyn Diagnostic> from some part of your program's error handling, you may wanna inspect or manipulate the diagnostic's data programmatically instead of just printing it out.
  • This would also be useful for serialization, logging, or custom reporting, where concrete data is needed rather than a trait object.

zkat mentioned in #285 that a PR would be welcome, so this implements that.

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 this pull request may close these issues.

Implement From<Box<dyn Diagnostic>> for MietteDiagnostic

2 participants