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

unwrap is not that safe ... #39

Open
jrouaix opened this issue Nov 19, 2024 · 3 comments
Open

unwrap is not that safe ... #39

jrouaix opened this issue Nov 19, 2024 · 3 comments

Comments

@jrouaix
Copy link

jrouaix commented Nov 19, 2024

Hello,

it seems that an unwrap considered safe, is panicking.

let path = e.path().strip_prefix(self.ignore.path()).unwrap();

thread '<unnamed>' panicked at /home/..../index.crates.io-6f17d22bba15001f/globwalk-0.9.1/src/lib.rs:381:78:
called `Result::unwrap()` on an `Err` value: StripPrefixError(())
@jrouaix
Copy link
Author

jrouaix commented Nov 19, 2024

seems like the panic happen when those kind of values arrive in the strip_prefix function :

#[cfg(test)]
mod tests {
  use std::path::PathBuf;

  #[test]
  fn a_test() {
    let path = PathBuf::from("./plop.file");
    path.strip_prefix("plop.file").unwrap();
  }
}
called `Result::unwrap()` on an `Err` value: StripPrefixError(())
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed

@Gilnaa
Copy link
Owner

Gilnaa commented Nov 20, 2024

What invocation of globwalk did you use to get this?
What crate versions do you have in your lockfile?

@jrouaix
Copy link
Author

jrouaix commented Nov 21, 2024

lock file is on the latest version

[[package]]
name = "globwalk"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bf760ebf69878d9fd8f110c89703d90ce35095324d1f1edcb595c63945ee757"
dependencies = [
 "bitflags 2.5.0",
 "ignore",
 "walkdir",
]

a failing case would be as simple as this one :

#[cfg(test)]
mod tests {
  #[test]
  fn test() -> anyhow::Result<()> {
    let all_files = globwalk::GlobWalkerBuilder::from_patterns("./src", &[""])
      .build()?
      .filter_map(Result::ok);

    for file in all_files {
      dbg!(file);
    }
    Ok(())
  }
}

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