Skip to content

Commit

Permalink
improve policy output parsing error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
wookietreiber committed Sep 4, 2024
1 parent dc5e78a commit 7e6d37d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
22 changes: 6 additions & 16 deletions src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,34 +100,24 @@ impl Entry<'_> {
const INVALID: &'static str = "invalid line in policy report";

pub fn inode_str(&self) -> Result<&str> {
self.0[0]
.to_str()
.context("reading inode field from policy report")
self.0[0].to_str().context("reading inode field")
}

pub fn bytes_str(&self) -> Result<&str> {
self.0[4]
.to_str()
.context("reading bytes field from policy report")
self.0[4].to_str().context("reading bytes field")
}

pub fn bytes(&self) -> Result<u64> {
self.bytes_str().and_then(|s| {
s.parse::<u64>()
.context("parsing bytes field from policy report")
})
self.bytes_str()
.and_then(|s| s.parse().context("parsing bytes field"))
}

pub fn nlink_str(&self) -> Result<&str> {
self.0[5]
.to_str()
.context("reading number of links field from policy report")
self.0[5].to_str().context("reading number of links field")
}

pub fn path(&self) -> Result<&Path> {
self.1
.to_path()
.context("parsing path field from policy report")
self.1.to_path().context("parsing path field")
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/usage/total.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ pub fn sum(report: impl Read, count_links: bool) -> Result<Acc> {

for line in BufReader::new(report).byte_lines() {
let line = line.context("reading line from policy report")?;
let entry = Entry::try_from(&line)?;

let entry = Entry::try_from(&line)
.context("parsing line from policy report")?;

let bytes = entry.bytes()?;

Expand Down

0 comments on commit 7e6d37d

Please sign in to comment.