-
-
Notifications
You must be signed in to change notification settings - Fork 124
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
miette fails silently when span is wrong #219
Comments
Could you send an example of the input that you're providing, so I can try to reproduce this behavior? There are several different ways that a span can be wrong, and I'm not sure exactly what's going on here. |
I don't have one anymore, but basically if the span in your error points to an offset that's too far off the size of your source, then this will happen. For example using |
This bit me too and it was fairly confusing. |
Got hit by that too because I emitted spans which were |
Yeah this doesn't look great. :\ I don't have time to get to it myself right now, but if anyone wants to talk about potential solutions, I'm all for it. It's kinda tricky to figure out what a failure coming from a failure library should even look like (should it panic?) |
Just to have a minimal example, this: use miette::{Diagnostic, SourceSpan, Result};
use thiserror::Error;
#[derive(Debug, Diagnostic, Error)]
#[error("parse error")]
struct ParseError {
#[source_code]
src: &'static str,
#[label("uh oh")]
wrong: SourceSpan,
}
fn main() -> Result<()> {
Err(ParseError {
src: "did a fucky",
wrong: (6, 11).into(),
})?;
Ok(())
} outputs:
while changing the span to
while using the JSON handler with the first works fine (it happily outputs 'wrong' spans). |
I think there's a number of points to improve on:
|
an easy way to fix this is to panic only in debug mode, another idea is to change the error message to say something like "the given span does not correctly fit in the source file" |
Fixes: zkat#219 When a snippet couldn't be read (typically because the span didn't fit within the source code), it and the rest of the diagnostic were silently dropped, which was confusing to the developer. Now, in place of the snippet, print an error message with the name of the failed label and the error it triggered, then proceed with the rest of the diagnostic (footer, related, ...)
Fixes: zkat#219 When a snippet couldn't be read (typically because the span didn't fit within the source code), it and the rest of the diagnostic were silently dropped, which was confusing to the developer. Now, in place of the snippet, print an error message with the name of the failed label and the error it triggered, then proceed with the rest of the diagnostic (footer, related, ...)
Fixes: #219 When a snippet couldn't be read (typically because the span didn't fit within the source code), it and the rest of the diagnostic were silently dropped, which was confusing to the developer. Now, in place of the snippet, print an error message with the name of the failed label and the error it triggered, then proceed with the rest of the diagnostic (footer, related, ...)
OK I now understand why I just get an error message without the full beautiful report:
it's because my span is wrong. It would have been nice if an error would have been thrown so that it's easier to understand why no report is displayed : o
The text was updated successfully, but these errors were encountered: