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

fix(invalid span): skip the snippet when read_span fails #347

Merged
merged 1 commit into from
Feb 21, 2024

Conversation

Nahor
Copy link
Contributor

@Nahor Nahor commented Feb 21, 2024

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, ...)

This is what it looks like:
image

writeln!(
f,
" [{} `{}`: {:?}]",
"no snippet, error in label".style(self.theme.styles.error),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"no snippet, error in label".style(self.theme.styles.error),
"Failed to read contents for label".style(self.theme.styles.error),

Err(err) => {
writeln!(
f,
" [{} `{}`: {:?}]",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should print the source name, at least. Possibly the span, as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no name at this point. We only have a SourceCode trait object, which will give the name but only if the read_span succeeds.

@Nahor
Copy link
Contributor Author

Nahor commented Feb 21, 2024

The CI failure should be addressed with #348

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, ...)
@zkat zkat merged commit 7d9dfc6 into zkat:main Feb 21, 2024
10 of 14 checks passed
@Nahor Nahor deleted the out_of_bounds branch February 21, 2024 21:47
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.

miette fails silently when span is wrong
2 participants