2024-04-21 18:47:07 +01:00
|
|
|
use crate::server::config::{BranchName, GitDir};
|
2024-04-16 22:21:55 +01:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum ForgeFileError {
|
|
|
|
NotFound(String),
|
|
|
|
ParseContent,
|
|
|
|
DecodeFromBase64,
|
|
|
|
DecodeFromUtf8,
|
|
|
|
UnknownEncoding(String),
|
|
|
|
NotFile(String),
|
|
|
|
Unknown(String),
|
|
|
|
}
|
|
|
|
impl std::error::Error for ForgeFileError {}
|
|
|
|
impl std::fmt::Display for ForgeFileError {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
match self {
|
|
|
|
Self::NotFound(file_path) => write!(f, "File not found: {file_path}"),
|
|
|
|
Self::NotFile(file_path) => write!(f, "Not a file: {file_path}"),
|
|
|
|
Self::DecodeFromBase64 => write!(f, "Unable to decode from base64"),
|
|
|
|
Self::DecodeFromUtf8 => write!(f, "Unable to decode from UTF-8"),
|
|
|
|
Self::UnknownEncoding(encoding) => write!(f, "Unknown file encoding: {encoding}"),
|
|
|
|
Self::ParseContent => write!(f, "Unable to parse file contents"),
|
|
|
|
Self::Unknown(status) => write!(f, "Unknown error (status: {status})"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum ForgeBranchError {
|
|
|
|
NotFound(BranchName),
|
|
|
|
NoneFound,
|
|
|
|
}
|
|
|
|
impl std::error::Error for ForgeBranchError {}
|
|
|
|
impl std::fmt::Display for ForgeBranchError {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
match self {
|
|
|
|
Self::NotFound(branch_name) => write!(f, "Branch not found: {branch_name}"),
|
|
|
|
Self::NoneFound => write!(f, "Unable to find any branches"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-19 18:56:42 +01:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum RepoCloneError {
|
2024-04-21 18:47:07 +01:00
|
|
|
InvalidGitDir(GitDir),
|
2024-04-24 07:08:03 +01:00
|
|
|
Io(std::io::Error),
|
2024-04-19 18:56:42 +01:00
|
|
|
Wait(std::io::Error),
|
|
|
|
Spawn(std::io::Error),
|
2024-04-24 07:08:03 +01:00
|
|
|
Validation(String),
|
2024-04-27 15:23:42 +01:00
|
|
|
GixClone(Box<gix::clone::Error>),
|
2024-05-09 21:18:40 +01:00
|
|
|
GixOpen(Box<gix::open::Error>),
|
2024-04-27 15:23:42 +01:00
|
|
|
GixFetch(Box<gix::clone::fetch::Error>),
|
2024-04-19 18:56:42 +01:00
|
|
|
}
|
|
|
|
impl std::error::Error for RepoCloneError {}
|
|
|
|
impl std::fmt::Display for RepoCloneError {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
match self {
|
|
|
|
Self::InvalidGitDir(gitdir) => write!(f, "Invalid Git dir: {:?}", gitdir),
|
2024-04-24 07:08:03 +01:00
|
|
|
Self::Io(err) => write!(f, "IO error: {:?}", err),
|
2024-04-19 18:56:42 +01:00
|
|
|
Self::Wait(err) => write!(f, "Waiting for command: {:?}", err),
|
|
|
|
Self::Spawn(err) => write!(f, "Spawning comming: {:?}", err),
|
2024-04-24 07:08:03 +01:00
|
|
|
Self::Validation(err) => write!(f, "Validation: {}", err),
|
2024-04-27 15:23:42 +01:00
|
|
|
Self::GixClone(err) => write!(f, "Clone: {:?}", err),
|
2024-05-09 21:18:40 +01:00
|
|
|
Self::GixOpen(err) => write!(f, "Open: {:?}", err),
|
2024-04-27 15:23:42 +01:00
|
|
|
Self::GixFetch(err) => write!(f, "Fetch: {:?}", err),
|
2024-04-19 18:56:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-27 15:23:42 +01:00
|
|
|
impl From<gix::clone::Error> for RepoCloneError {
|
|
|
|
fn from(value: gix::clone::Error) -> Self {
|
|
|
|
Self::GixClone(Box::new(value))
|
|
|
|
}
|
|
|
|
}
|
2024-05-09 21:18:40 +01:00
|
|
|
impl From<gix::open::Error> for RepoCloneError {
|
|
|
|
fn from(value: gix::open::Error) -> Self {
|
|
|
|
Self::GixOpen(Box::new(value))
|
|
|
|
}
|
|
|
|
}
|
2024-04-27 15:23:42 +01:00
|
|
|
impl From<gix::clone::fetch::Error> for RepoCloneError {
|
|
|
|
fn from(value: gix::clone::fetch::Error) -> Self {
|
|
|
|
Self::GixFetch(Box::new(value))
|
|
|
|
}
|
|
|
|
}
|