summaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorSebastian Thiel <sthiel@thoughtworks.com>2019-06-01 12:36:24 +0530
committerSebastian Thiel <sthiel@thoughtworks.com>2019-06-01 12:36:24 +0530
commitc1cbcf355755fbd1ca6124cdba3b8e361a7bebf2 (patch)
tree4f2120ad0e7546423bec08711df84984fc0bfd6c /src/lib.rs
parentc50332cead2688e40de192e1b47e50a662763a78 (diff)
Better error reporting
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/lib.rs b/src/lib.rs
index c4d2cf5..0f7627a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -39,12 +39,12 @@ mod common {
#[derive(Default)]
pub struct WalkResult {
- pub num_errors: usize,
+ pub num_errors: u64,
}
impl fmt::Display for WalkResult {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
- write!(f, "Encountered {} IO errors", self.num_errors)
+ write!(f, "Encountered {} IO error(s)", self.num_errors)
}
}
}
@@ -52,6 +52,7 @@ mod common {
mod aggregate {
use crate::{WalkOptions, WalkResult};
use failure::Error;
+ use std::borrow::Cow;
use std::{io, path::Path};
pub fn aggregate(
@@ -65,6 +66,7 @@ mod aggregate {
for path in paths.into_iter() {
num_roots += 1;
let mut num_bytes = 0u64;
+ let mut num_errors = 0u64;
for entry in options.iter_from_path(path.as_ref()) {
match entry {
Ok(entry) => {
@@ -72,7 +74,7 @@ mod aggregate {
Some(Ok(ref m)) if !m.is_dir() => m.len(),
Some(Ok(_)) => 0,
Some(Err(_)) => {
- res.num_errors += 1;
+ num_errors += 1;
0
}
None => unreachable!(
@@ -80,15 +82,16 @@ mod aggregate {
),
};
}
- Err(_) => res.num_errors += 1,
+ Err(_) => num_errors += 1,
}
}
- write_path(&mut out, &options, path, num_bytes)?;
+ write_path(&mut out, &options, path, num_bytes, num_errors)?;
total += num_bytes;
+ res.num_errors += num_errors;
}
if num_roots > 1 {
- write_path(&mut out, &options, Path::new("<TOTAL>"), total)?;
+ write_path(&mut out, &options, Path::new("total"), total, res.num_errors)?;
}
Ok(res)
}
@@ -98,12 +101,18 @@ mod aggregate {
options: &WalkOptions,
path: impl AsRef<Path>,
num_bytes: u64,
+ num_errors: u64,
) -> Result<(), io::Error> {
writeln!(
out,
- "{}\t{}",
+ "{}\t{}{}",
options.format_bytes(num_bytes),
- path.as_ref().display()
+ path.as_ref().display(),
+ if num_errors == 0 {
+ Cow::Borrowed("")
+ } else {
+ Cow::Owned(format!("\t<{} IO Error(s)>", num_errors))
+ }
)
}
}