From ea1ace826186fa008ff1fa64f1125f435ea0cedb Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Wed, 30 Nov 2022 03:17:47 -0600 Subject: refactor: merge error types into single enum --- src/project/error.rs | 15 --------------- src/project/git.rs | 15 +++++++++------ 2 files changed, 9 insertions(+), 21 deletions(-) delete mode 100644 src/project/error.rs (limited to 'src/project') diff --git a/src/project/error.rs b/src/project/error.rs deleted file mode 100644 index 2e9f4a3..0000000 --- a/src/project/error.rs +++ /dev/null @@ -1,15 +0,0 @@ -#[derive(thiserror::Error, Debug)] -pub enum Error { - #[error(transparent)] - IO(#[from] std::io::Error), - - #[cfg(feature = "git")] - #[error(transparent)] - Git(#[from] git2::Error), - - #[error(transparent)] - SystemTime(#[from] std::time::SystemTimeError), - - #[error(transparent)] - Other(#[from] anyhow::Error), -} diff --git a/src/project/git.rs b/src/project/git.rs index 759f632..6c8f329 100644 --- a/src/project/git.rs +++ b/src/project/git.rs @@ -5,7 +5,9 @@ use std::io; use std::{path::PathBuf, time::Duration}; use tracing::{debug, warn}; -use super::{Error, Preview, ProjectParser, Timestamp}; +use crate::{Error, Result}; + +use super::{Preview, ProjectParser, Timestamp}; #[derive(Debug, Clone)] pub struct GitMatcher; @@ -30,7 +32,7 @@ pub struct GitProject { } impl GitProject { - fn new(path_buf: PathBuf) -> Result { + fn new(path_buf: PathBuf) -> Result { let repo = Repository::open(&path_buf)?; let latest_commit = Self::get_timestamp(&repo); Ok(Self { @@ -49,7 +51,7 @@ impl GitProject { } } - fn latest_commit(repository: &Repository) -> Result { + fn latest_commit(repository: &Repository) -> Result { let mut branches = repository.branches(Some(BranchType::Local))?; branches.try_fold(0, |latest, branch| { let (branch, _) = branch?; @@ -62,6 +64,7 @@ impl GitProject { .revparse_single(name)? .peel_to_commit() .map(|c| (c.time().seconds() as u64).max(latest)) + .map_err(Into::into) }) } } @@ -76,7 +79,7 @@ impl Timestamp for GitProject { impl Preview for GitProject { type Error = Error; - fn preview(&self) -> Result<(), Self::Error> { + fn preview(&self) -> Result<()> { let config = onefetch::cli::Config { input: self.path_buf.to_owned(), include_hidden: true, @@ -99,7 +102,7 @@ impl AsRef for GitProject { impl TryFrom for GitProject { type Error = Error; - fn try_from(value: PathBuf) -> Result { + fn try_from(value: PathBuf) -> Result { Self::new(value) } } @@ -107,7 +110,7 @@ impl TryFrom for GitProject { impl TryFrom for GitProject { type Error = Error; - fn try_from(value: DirEntry) -> Result { + fn try_from(value: DirEntry) -> Result { Self::new(value.into_path()) } } -- cgit v1.2.3-70-g09d2