Remove git-specific error cases from origin errors

This commit is contained in:
Brian Picciano 2024-05-29 11:43:52 +02:00
parent 1a6f804289
commit 4075b3e2cd
4 changed files with 25 additions and 34 deletions

View File

@ -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<origin::SyncError> 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),
}

View File

@ -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")]

View File

@ -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(

View File

@ -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),