summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-11-03 21:44:04 +0000
committerJohn Turner <jturner.usa@gmail.com>2025-11-08 22:12:45 +0000
commit5fd26e7c81899fabc066d8eefc7a8ec2b27e6351 (patch)
treedcf791a23cd9bf8f6cc4a702aff5c2c23214f80b
parent772e645066dc90b619f4add64098a2777727fca4 (diff)
downloadgentoo-utils-5fd26e7c81899fabc066d8eefc7a8ec2b27e6351.tar.gz
improve repo error message by including the path in the error enum
-rw-r--r--src/ebuild/repo/mod.rs30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/ebuild/repo/mod.rs b/src/ebuild/repo/mod.rs
index 53ad6f7..f484e87 100644
--- a/src/ebuild/repo/mod.rs
+++ b/src/ebuild/repo/mod.rs
@@ -17,7 +17,9 @@ use crate::{
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("io error: {0}")]
- Io(#[from] io::Error),
+ Io(PathBuf, io::Error),
+ #[error("error while reading directory: {0:?}: {1}")]
+ ReadDir(PathBuf, io::Error),
#[error("failed to decode path: {0}")]
Unicode(PathBuf),
#[error("parser error: {0}")]
@@ -38,10 +40,10 @@ pub struct Category {
}
#[derive(Debug)]
-pub struct Categories(fs::ReadDir);
+pub struct Categories(PathBuf, fs::ReadDir);
#[derive(Debug)]
-pub struct Ebuilds(fs::ReadDir);
+pub struct Ebuilds(PathBuf, fs::ReadDir);
impl Repo {
pub fn new<P: AsRef<Path>>(path: P) -> Self {
@@ -51,15 +53,21 @@ impl Repo {
}
pub fn categories(&self) -> Result<Categories, Error> {
- Ok(Categories(fs::read_dir(
- self.path.as_path().join("metadata/md5-cache"),
- )?))
+ let path = self.path.as_path().join("metadata/md5-cache");
+
+ Ok(Categories(
+ path.clone(),
+ fs::read_dir(&path).map_err(|e| Error::Io(path, e))?,
+ ))
}
}
impl Category {
pub fn ebuilds(&self) -> Result<Ebuilds, Error> {
- Ok(Ebuilds(fs::read_dir(self.path.as_path())?))
+ Ok(Ebuilds(
+ self.path.clone(),
+ fs::read_dir(&self.path).map_err(|e| Error::Io(self.path.clone(), e))?,
+ ))
}
}
@@ -67,12 +75,12 @@ impl Iterator for Categories {
type Item = Result<Category, Error>;
fn next(&mut self) -> Option<Self::Item> {
- match self.0.next()? {
+ match self.1.next()? {
Ok(entry) => match read_category(entry.path()) {
Ok(category) => Some(Ok(category)),
Err(e) => Some(Err(e)),
},
- Err(e) => Some(Err(Error::Io(e))),
+ Err(e) => Some(Err(Error::ReadDir(self.0.clone(), e))),
}
}
}
@@ -81,7 +89,7 @@ impl Iterator for Ebuilds {
type Item = Result<Ebuild, Error>;
fn next(&mut self) -> Option<Self::Item> {
- match self.0.next()? {
+ match self.1.next()? {
Ok(entry) => match read_ebuild(entry.path()) {
Ok(ebuild) => Some(Ok(ebuild)),
Err(e) => Some(Err(e)),
@@ -119,7 +127,7 @@ fn read_ebuild(path: PathBuf) -> Result<Ebuild, Error> {
.parse_finished(InputIter::new(file_name))
.map_err(|_| Error::Parser(file_name.to_string()))?;
- let metadata = fs::read_to_string(path.as_path())?;
+ let metadata = fs::read_to_string(path.as_path()).map_err(|e| Error::Io(path, e))?;
Ok(Ebuild {
name,