From 4075b3e2cd56d616890577bdce1a21a97a8fde4a Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Wed, 29 May 2024 11:43:52 +0200 Subject: [PATCH] Remove git-specific error cases from origin errors --- src/domain/manager.rs | 12 ++++-------- src/origin.rs | 11 ++++------- src/origin/git.rs | 22 ++++++++++++++-------- src/service/http.rs | 14 +++----------- 4 files changed, 25 insertions(+), 34 deletions(-) diff --git a/src/domain/manager.rs b/src/domain/manager.rs index 5910bdd..80ea5d3 100644 --- a/src/domain/manager.rs +++ b/src/domain/manager.rs @@ -46,15 +46,12 @@ pub enum SyncWithSettingsError { #[error("domain's settings cannot be modified")] NotModifiable, - #[error("invalid url")] - InvalidURL, + #[error("invalid descr")] + InvalidDescr(String), - #[error("unavailable due to server-side issue")] + #[error("unavailable due to upstream issue")] Unavailable, - #[error("invalid branch name")] - InvalidBranchName, - #[error("already in progress")] AlreadyInProgress, @@ -71,9 +68,8 @@ pub enum SyncWithSettingsError { impl From for SyncWithSettingsError { fn from(e: origin::SyncError) -> SyncWithSettingsError { match e { - origin::SyncError::InvalidURL => SyncWithSettingsError::InvalidURL, + origin::SyncError::InvalidDescr(msg) => SyncWithSettingsError::InvalidDescr(msg), origin::SyncError::Unavailable => SyncWithSettingsError::Unavailable, - origin::SyncError::InvalidBranchName => SyncWithSettingsError::InvalidBranchName, origin::SyncError::AlreadyInProgress => SyncWithSettingsError::AlreadyInProgress, origin::SyncError::Unexpected(e) => SyncWithSettingsError::Unexpected(e), } diff --git a/src/origin.rs b/src/origin.rs index e0ec013..ad962d1 100644 --- a/src/origin.rs +++ b/src/origin.rs @@ -9,15 +9,12 @@ use crate::util; #[derive(thiserror::Error, Clone, Debug, PartialEq)] pub enum SyncError { - #[error("invalid url")] - InvalidURL, + #[error("invalid descr")] + InvalidDescr(String), - #[error("unavailable due to server-side issue")] + #[error("unavailable due to upstream issue")] Unavailable, - #[error("invalid branch name")] - InvalidBranchName, - #[error("already in progress")] AlreadyInProgress, @@ -33,7 +30,7 @@ pub enum GetFileError { #[error("file not found")] FileNotFound, - #[error("unavailable due to server-side issue")] + #[error("unavailable due to upstream issue")] Unavailable, #[error("path is directory")] diff --git a/src/origin/git.rs b/src/origin/git.rs index 5fe9a05..87a037f 100644 --- a/src/origin/git.rs +++ b/src/origin/git.rs @@ -19,7 +19,7 @@ impl DescrState { #[derive(thiserror::Error, Clone, Debug, PartialEq)] enum GetObjectError { - #[error("unavailable due to server-side issue")] + #[error("unavailable due to upstream issue")] Unavailable, #[error(transparent)] @@ -84,15 +84,19 @@ impl Proxy { // (and therefore the URL) has some kind of issue. let refs = self .client - .get(refs_url) + .get(refs_url.clone()) .send() .await - .or(Err(origin::SyncError::InvalidURL))? + .map_err(|e| { + origin::SyncError::InvalidDescr(format!("fetching refs from {refs_url}: {e}")) + })? .error_for_status() - .or(Err(origin::SyncError::InvalidURL))? + .map_err(|e| { + origin::SyncError::InvalidDescr(format!("fetching refs from {refs_url}: {e}")) + })? .text() .await - .or(Err(origin::SyncError::InvalidURL))?; + .or(Err(origin::SyncError::Unavailable))?; let full_ref = format!("refs/heads/{}", branch_name); for line in refs.lines() { @@ -103,13 +107,15 @@ impl Proxy { return gix_hash::ObjectId::from_hex( line.split_ascii_whitespace() .next() - .ok_or(origin::SyncError::InvalidURL)? + .ok_or(origin::SyncError::Unavailable)? .as_bytes(), ) - .or(Err(origin::SyncError::InvalidURL)); + .or(Err(origin::SyncError::Unavailable)); } - Err(origin::SyncError::InvalidBranchName) + Err(origin::SyncError::InvalidDescr( + "Invalid branch name".to_string(), + )) } async fn get_object( diff --git a/src/service/http.rs b/src/service/http.rs index 4676440..860a187 100644 --- a/src/service/http.rs +++ b/src/service/http.rs @@ -425,20 +425,12 @@ impl Service { (Some("This domain is not allowed to be configured.".to_string()), false) } - Err(domain::manager::SyncWithSettingsError::InvalidURL) => (Some( - "Fetching the git repository failed; please double check that you input the correct - URL." - .to_string(), + Err(domain::manager::SyncWithSettingsError::InvalidDescr(msg)) => (Some( + format!("Fetching the origin failed; please double check that you input the settings correctly. The error returned was: {msg}").to_string(), ), false), Err(domain::manager::SyncWithSettingsError::Unavailable) => (Some( - "Fetching the git repository failed; the server is not available or is not corectly serving the repository." - .to_string(), - ), false), - - Err(domain::manager::SyncWithSettingsError::InvalidBranchName) => (Some( - "The git repository does not have a branch of the given name; please double check - that you input the correct name." + "Fetching the origin failed; the origin is not available or is behaving in an unexpected way." .to_string(), ), false),