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

color-spantrace: print_source_if_avail: can't extract source if working dir is crate in workspace #164

Open
d4h0 opened this issue Oct 9, 2020 · 3 comments

Comments

@d4h0
Copy link
Contributor

d4h0 commented Oct 9, 2020

Hi,

I'm debugging my PR for color_eyre at the moment. For some reason, the source code lines were not printed out.

The reason was, that I'm using a workspace and that tracing_core::metadata::Metadata contains a file path relative to the workspace, not my current working directory.

So I'm in "$workspace/color_eyre" and execute a test.

This line is then executed because filename is "color-spantrace/tests/color_schemes.rs" – which is relative to the workspace, not my current working directory:

        // `filename` can't be found, because it's relative to the workspace
        let file = match File::open(filename) {
            Ok(file) => file,
            // return without printing the source:
            Err(ref e) if e.kind() == ErrorKind::NotFound => return Ok(()),
            e @ Err(_) => e.unwrap(),
        };

I believe this is only a problem for people who work on color_spantrace, and not for end-users who install color_spantrace via cargo (but I'm not 100% sure).

I'm reporting this in case there is an easy workaround (I can't see one), or in case this could lead to problems for end-users.

Feel free, to close this if you don't think this is a problem.

Maybe a note in the README for people who want to work on color_spantrace would make sense?

@d4h0
Copy link
Contributor Author

d4h0 commented Oct 9, 2020

Basically, normally you'd get the following:

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ SPANTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  
   0: styles::get_error with msg="test"
      at tests/styles.rs:13
        11 │ 
        12 │ #[rustfmt::skip]
        13 > #[tracing::instrument]
        14 │ fn get_error(msg: &'static str) -> Report {
        15 │ 

Because of the bug I got:

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ SPANTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  
   0: styles::get_error with msg="test"
      at tests/styles.rs:13

@yaahc
Copy link
Collaborator

yaahc commented Oct 9, 2020

Aah yea, I have a PR that attempts to fix this but I never figured out the proper way to resolve the relative paths we should be searching in and ended up forgetting about the PR, I should really try to finish that one...

@d4h0
Copy link
Contributor Author

d4h0 commented Oct 10, 2020

I think Cargo should offer the root directory of the current base directory (the workspace or the standalone dir) as an environment variable, but it seems this doesn't exist.

Maybe OUT_DIR or CARGO_MANIFEST_DIR could be used to derive the right directory?

@pksunkara pksunkara transferred this issue from eyre-rs/color-spantrace Mar 30, 2024
@pksunkara pksunkara changed the title print_source_if_avail: can't extract source if working dir is crate in workspace color-spantrace: print_source_if_avail: can't extract source if working dir is crate in workspace Mar 30, 2024
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

No branches or pull requests

2 participants