globwalk icon indicating copy to clipboard operation
globwalk copied to clipboard

`unwrap` is not that safe ...

Open jrouaix opened this issue 1 year ago • 3 comments

Hello,

it seems that an unwrap considered safe, is panicking.

https://github.com/Gilnaa/globwalk/blob/8973fa2bc560be54c91448131238fa50d56ee121/src/lib.rs#L381

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 avatar Nov 19 '24 09:11 jrouaix

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

jrouaix avatar Nov 19 '24 09:11 jrouaix

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

Gilnaa avatar Nov 20 '24 04:11 Gilnaa

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(())
  }
}

jrouaix avatar Nov 21 '24 10:11 jrouaix