Skip to content

Commit

Permalink
Converts a panic into an error and rearranges things around it [fix]
Browse files Browse the repository at this point in the history
  • Loading branch information
hoijui committed Dec 5, 2023
1 parent 0e6e2a6 commit 6db9531
Showing 1 changed file with 35 additions and 32 deletions.
67 changes: 35 additions & 32 deletions src/file_traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,40 +64,43 @@ pub fn add(config: &Config, file: &Path, result: &mut Vec<File>) -> Result<(), E
let markup_types = &config.markup_types;
let ignore_paths = &config.ignore_paths;

if let Some(file_name) = file.file_name().map(OsStr::to_string_lossy) {
markup_type(&file_name, markup_types).map_or_else(
|| {
trace!(
"Not a file of a configured markup type: '{}'",
file.display()
);
},
|markup_type| {
let abs_path = fs::canonicalize(file).expect("Expected path to exist.");
if ignore_paths
.iter()
.any(|ignore_path| ignore_path.matches(&abs_path))
{
debug!(
"Ignoring file '{}', because it is in the ignore paths list.",
file.file_name().map(OsStr::to_string_lossy).map_or_else(
|| Err(Error::MissingFileName(file.to_path_buf())),
|file_name| {
markup_type(&file_name, markup_types).map_or_else(
|| {
trace!(
"Not a file of a configured markup type: '{}'",
file.display()
);
} else {
let markup_file = File {
markup_type,
locator: Rc::new(FileLoc::System(FileSystemLoc::from(file))),
content: Content::LocalFile(file.to_owned()),
start: Position::new(),
};
debug!("Found file: '{:?}'", markup_file);
result.push(markup_file);
}
},
);
} else {
return Err(Error::MissingFileName(file.to_path_buf()));
}
Ok(())
Ok(())
},
|markup_type| {
let abs_path = fs::canonicalize(file)
.map_err(|_err| Error::NonexistentPath(file.to_owned()))?;
if ignore_paths
.iter()
.any(|ignore_path| ignore_path.matches(&abs_path))
{
debug!(
"Ignoring file '{}', because it is in the ignore paths list.",
file.display()
);
} else {
let markup_file = File {
markup_type,
locator: Rc::new(FileLoc::System(FileSystemLoc::from(file))),
content: Content::LocalFile(file.to_owned()),
start: Position::new(),
};
debug!("Found file: '{:?}'", markup_file);
result.push(markup_file);
}
Ok(())
},
)
},
)
}

/// Searches for markup source files acording to the configuration,
Expand Down

0 comments on commit 6db9531

Please sign in to comment.