Hi, I'm trying to convert the following piece of code that is using panic!
into something with more robust error handling where I'd like to use .context("...")
from anyhow. Do you know of a nice way to rewrite this?
let absolute_paths: HashSet<PathBuf> = globs
.iter()
// join expanded globs for each pattern
.flat_map(|pattern| {
glob(pattern)
.unwrap_or_else(|_| panic!(format!("Failed to read glob pattern {}", pattern)))
})
// filter out errors
.filter_map(|x| x.ok())
// canonical form of paths
.map(|path| {
path.canonicalize()
.unwrap_or_else(|_| panic!(format!("Error in canonicalize of {:?}", path)))
})
// collect into a set of unique values
.collect();