diff options
Diffstat (limited to 'lib/libgfold/src/collector.rs')
-rw-r--r-- | lib/libgfold/src/collector.rs | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/libgfold/src/collector.rs b/lib/libgfold/src/collector.rs index b80066e..ca80682 100644 --- a/lib/libgfold/src/collector.rs +++ b/lib/libgfold/src/collector.rs @@ -4,11 +4,24 @@ use rayon::prelude::*; use std::collections::BTreeMap; use std::path::Path; use target::TargetCollector; +use thiserror::Error; -use crate::repository_view::RepositoryView; +use crate::repository_view::{RepositoryView, RepositoryViewError, RepositoryViewResult}; mod target; +#[allow(missing_docs)] +#[derive(Error, Debug)] +pub enum CollectorError { + #[error(transparent)] + FromRepositoryView(#[from] RepositoryViewError), + #[error(transparent)] + FromStdIo(#[from] std::io::Error), +} + +/// The result type used when multiple kinds of errors can be encountered during collection. +pub type CollectorResult<T> = Result<T, CollectorError>; + /// This type represents a [`BTreeMap`] using an optional [`String`] for keys, which represents the /// parent directory for a group of reports ([`Vec<RepositoryView>`]). The values corresponding to those keys /// are the actual groups of reports. @@ -17,9 +30,10 @@ mod target; /// sorted keys. pub type RepositoryCollection = BTreeMap<Option<String>, Vec<RepositoryView>>; -type UnprocessedRepositoryView = anyhow::Result<RepositoryView>; +type UnprocessedRepositoryView = RepositoryViewResult<RepositoryView>; /// A unit struct that provides [`Self::run()`], which is used to generated [`RepositoryCollection`]. +#[derive(Debug)] pub struct RepositoryCollector; impl RepositoryCollector { @@ -28,7 +42,7 @@ impl RepositoryCollector { path: &Path, include_email: bool, include_submodules: bool, - ) -> anyhow::Result<RepositoryCollection> { + ) -> CollectorResult<RepositoryCollection> { let unprocessed = TargetCollector::run(path.to_path_buf())? .par_iter() .map(|path| RepositoryView::new(path, include_email, include_submodules)) @@ -45,7 +59,7 @@ impl RepositoryCollector { processed.insert(view.parent, views); } } - Err(e) => return Err(e), + Err(e) => return Err(e.into()), } } Ok(processed) |