miette
miette copied to clipboard
Awkward spacing with `#[related]` errors with `#[diagnostic(code)]`s
Example:
use {
miette::{Diagnostic, SourceSpan},
thiserror::Error,
};
#[derive(Debug, Error, Diagnostic)]
#[error("{} errors", .related.len())]
struct Errors {
#[source_code]
src: String,
#[related]
related: Vec<Error>,
}
#[derive(Debug, Error, Diagnostic)]
#[error("some error")]
#[diagnostic(code("example::error"))]
struct Error {
#[label]
span: SourceSpan,
}
fn main() -> miette::Result<()> {
Err(Errors {
src: "test test".into(),
related: vec![
Error {
span: (0..4).into(),
},
Error {
span: (5..9).into(),
},
],
})?;
Ok(())
}
Error:
× 2 errors
Error: example::error
× some error
╭────
1 │ test test
· ────
╰────
Error: example::error
× some error
╭────
1 │ test test
· ────
╰────
The empty line between the error code and the rendered error causes the errors to visually group incorrectly; either diagnostics should never have any blank lines, or #[related]
needs to put blank lines between the related diagnostics.
Without the diagnostic code, the blank line is not present and the visual grouping is fine:
Error:
× 2 errors
Error:
× some error
╭────
1 │ test test
· ────
╰────
Error:
× some error
╭────
1 │ test test
· ────
╰────