forked from gentoo-utils/gentoo-utils
improve repo error message by including the path in the error enum
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user