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

Bad span pointing when single line span supersets a prior span #135

Open
CAD97 opened this issue Mar 18, 2022 · 3 comments
Open

Bad span pointing when single line span supersets a prior span #135

CAD97 opened this issue Mar 18, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@CAD97
Copy link
Contributor

CAD97 commented Mar 18, 2022

Excerpt:

use miette::{Diagnostic, ErrReport, Result, SourceSpan};
use thiserror::Error;

#[derive(Debug, Error, Diagnostic)]
#[diagnostic(severity(warning))]
pub enum Warning {
    #[error("invalid target directive specified")]
    #[diagnostic(code(tracing_filter::simple::Warning::InvalidTarget), url(docsrs))]
    InvalidTarget {
        #[label("this `=` is not allowed ...")]
        equals: SourceSpan,
        #[label("... in this target directive")]
        target: SourceSpan,
    },
}

pub fn main() -> Result<()> {
    Err(ErrReport::from(Warning::InvalidTarget {
        equals: (5..6).into(),
        target: (0..12).into(),
    })
    .with_source_code("crate=target=warn"))
}
Error: tracing_filter::simple::Warning::InvalidTarget (link)

  ⚠ invalid target directive specified
   ╭────
 1 │ crate=target=warn
   · ──────┬─────
   ·       │╰── this `=` is not allowed ...
   ·       ╰── ... in this target directive
   ╰────

image

This is, admittedly, a rather degenerate case. But the span is clearly pointing not at the desired location.

If the point is after the halfway point, it works:

Error: tracing_filter::simple::Warning::InvalidTarget (link)

  ⚠ invalid target directive specified
   ╭────
 1 │ xxxxxxxxxxxxxxxxxxxxxxxxxxxx=xx=warn
   · ───────────────┬───────────────
   ·                │            ╰── this `=` is not allowed ...
   ·                ╰── ... in this target directive
   ╰────

image

but if the point is before the halfway point, it gets shoved "out of the way" of the latter span's stem, arbitrarily far from where it's supposed to point:

Error: tracing_filter::simple::Warning::InvalidTarget (link)

  ⚠ invalid target directive specified
   ╭────
 1 │ xx=xxxxxxxxxxxxxxxxxxxxxxxxxxxx=warn
   · ───────────────┬───────────────
   ·                │╰── this `=` is not allowed ...
   ·                ╰── ... in this target directive
   ╰────

image

@zkat
Copy link
Owner

zkat commented Mar 19, 2022

tbh while it's weird, I'm inclined to mark this as "wontfix". When I was writing this, I intentionally decided not to bother making them overlap because I assumed it would make the rendering logic way too complicated and/or the errors not very readable/helpful. Like, what's the "correct" way to display this? I don't know! Anything I can come up with is awful and I think this is a "don't give miette overlapping spans" sort of thing tbh.

@zkat zkat added the enhancement New feature or request label Mar 19, 2022
@CAD97
Copy link
Contributor Author

CAD97 commented Mar 19, 2022

I could've sworn that rustc emitted errors with a large superset span in some cases, but I can't figure out when it occurs or find an example. Specifically, I feel like I've seen:

   ╭─[1:1]
 1 │
 2 │ ╭─▶︎ 123456789
 3 │ │   123456789
   · │     ──┬─
   · │       ╰── inner span
 4 │ ├─▶︎ 123456789
   · ╰──── outer span
   ╰────

(GitHub's ▶︎ is slightly more than a cell wide... and I event applied the text presentation selector to remove the emoji presentation default)

The lines for this case don't have to overlap, but miette still chokes rather interestingly. The above is cleaned, and what miette actually gave is completely broken:

   ╭─[1:1]
 1 │
 2 │ ╭─▶︎ 123456789
 3 │ │╭▶︎ 123456789
   · ││    ──┬─
   · ││      ╰── inner span
 4 │ ├─▶︎ 123456789
   · ╰──── outer span
   ╰────

image

I'll rethink the structure of these warnings to avoid overlapping the spans, then.

(I think my ideal warning would be smth like

Warning: tracing_filter::simple::Warning::InvalidDirective

  ⚠ invalid directive specified
   ╭────
 1 │ crate=target=warn
   ·      ┬      ┬
   ·      ╰──────┴─── only one `=` is allowed
   ╰────

)

@jdonszelmann
Copy link
Contributor

jdonszelmann commented Nov 9, 2023

The last bug highlighted here (with the two arrow lines in the gutter) is fixed with #316

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants