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

Unexpected behaviour on empty span #277

Open
indietyp opened this issue Jul 2, 2023 · 2 comments
Open

Unexpected behaviour on empty span #277

indietyp opened this issue Jul 2, 2023 · 2 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@indietyp
Copy link

indietyp commented Jul 2, 2023

I have been trying to model when an unexpected EOF occurs; the current behavior of empty spans in the fancy reporter is a bit puzzling to me.

In the example shown below, a span of 8..9 yields (which is expected):

image

Now my intuition (and AFAIK most tools) would say that the EOF of the string is at 9..9, setting 9..9 as the span yields:

image

Meanwhile, 8..8 yields:

image

I would've expected that 8..8 points before c (as c @ 8..9) and not after the character and 9..9 points to where 8..8 currently points to.

Do you know if this is expected behavior?

Minimal Reproducible Example

//! ```cargo
//! [dependencies]
//! miette = {version = "5.9.0", features = ["fancy"]}
//! ```
use miette::miette;
use miette::LabeledSpan;

fn main() {
    let report = miette!(
        labels = vec![LabeledSpan::at(8..8, "Unexpected EOF")],
        "Generic Error"
    ).with_source_code("a = b + c");
    
    println!("{report:?}");
}
@Benjamin-L
Copy link
Contributor

This is effectively a bug, and the output for 9..9 should be:

  × Generic Error
   ╭────
 1 │ a = b + c
   ·          ▲
   ·          ╰── Unexpected EOF
   ╰────

I have a fix for this for the graphical report handler, but haven't successfully ported it over to the narratable handler yet. Ideally I'd like to keep the two in feature parity as much as possible, and I want to hold off on submitting a PR until I've got it working for both. I'll probably have time to take another shot at that later this week.

Longer term, the best path is probably to factor a lot of the duplicated logic between the graphical and narratable handlers into a central place. I have some ideas here, but it's gonna be more work than just fixing this one bug in both places.

@zkat
Copy link
Owner

zkat commented Jul 8, 2023

@Benjamin-L I'll just assign it to you for now, since you're already on it.

@zkat zkat added bug Something isn't working help wanted Extra attention is needed labels Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants