feat(status): add error context
This commit was merged in pull request #70.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use clap::Parser;
|
||||
use status::ResultExt;
|
||||
use std::path::{Path, PathBuf};
|
||||
use xatu::SourceFile;
|
||||
|
||||
@@ -26,7 +27,8 @@ fn is_excluded_dir(path: &Path) -> bool {
|
||||
}
|
||||
|
||||
fn collect_source_files(path: &Path) -> status::Result<Vec<SourceFile>> {
|
||||
let metadata = std::fs::symlink_metadata(path)?;
|
||||
let metadata = std::fs::symlink_metadata(path)
|
||||
.with_context(|| format!("failed to read metadata for {}", path.display()))?;
|
||||
|
||||
if metadata.file_type().is_dir() {
|
||||
if is_excluded_dir(path) {
|
||||
@@ -35,8 +37,11 @@ fn collect_source_files(path: &Path) -> status::Result<Vec<SourceFile>> {
|
||||
|
||||
let mut files = Vec::new();
|
||||
|
||||
for entry in std::fs::read_dir(path)? {
|
||||
let entry = entry?;
|
||||
for entry in std::fs::read_dir(path)
|
||||
.with_context(|| format!("failed to read directory {}", path.display()))?
|
||||
{
|
||||
let entry =
|
||||
entry.with_context(|| format!("failed to read entry in {}", path.display()))?;
|
||||
files.extend(collect_source_files(&entry.path())?);
|
||||
}
|
||||
|
||||
@@ -46,7 +51,8 @@ fn collect_source_files(path: &Path) -> status::Result<Vec<SourceFile>> {
|
||||
if metadata.file_type().is_file() && is_nix_file(path) {
|
||||
return Ok(vec![SourceFile {
|
||||
path: path.to_path_buf(),
|
||||
source: std::fs::read_to_string(path)?,
|
||||
source: std::fs::read_to_string(path)
|
||||
.with_context(|| format!("failed to read source file {}", path.display()))?,
|
||||
}]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user