git-next/crates/core/src/git/file.rs

82 lines
1.9 KiB
Rust
Raw Normal View History

//
pub type Result<T> = core::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
2024-05-23 16:50:36 +01:00
pub enum Error {
#[error("lock")]
Lock,
#[error("File not found: {}", 0)]
2024-05-23 16:50:36 +01:00
NotFound(String),
#[error("Unable to parse file contents")]
2024-05-23 16:50:36 +01:00
ParseContent,
#[error("Unable to decode from base64")]
2024-05-23 16:50:36 +01:00
DecodeFromBase64,
#[error("Unable to decode from UTF-8")]
2024-05-23 16:50:36 +01:00
DecodeFromUtf8,
#[error("Unknown file encoding: {}", 0)]
2024-05-23 16:50:36 +01:00
UnknownEncoding(String),
#[error("Not a file: {}", 0)]
2024-05-23 16:50:36 +01:00
NotFile(String),
#[error("Unknown error (status: {})", 0)]
2024-05-23 16:50:36 +01:00
Unknown(String),
#[error("commit log: {0}")]
CommitLog(#[from] crate::git::commit::log::Error),
#[error("commit not found")]
CommitNotFound,
#[error("no tree in commit")]
NoTreeInCommit(String),
#[error("no .git-next.toml file found in repo")]
2024-06-09 10:21:09 +01:00
FileNotFound,
#[error("find reference: {0}")]
FindReference(String),
#[error("find object: {0}")]
FindObject(String),
#[error("Non-UTF-8 in blob: {0}")]
NonUtf8Blob(String),
#[error("try id")]
TryId,
2024-05-23 16:50:36 +01:00
}
mod gix_errors {
#![cfg(not(tarpaulin_include))] // third-party library errors
use super::Error;
impl From<gix::reference::find::existing::Error> for Error {
fn from(value: gix::reference::find::existing::Error) -> Self {
Self::FindReference(value.to_string())
}
}
impl From<gix::object::commit::Error> for Error {
fn from(value: gix::object::commit::Error) -> Self {
Self::NoTreeInCommit(value.to_string())
}
}
impl From<gix::object::find::existing::Error> for Error {
fn from(value: gix::object::find::existing::Error) -> Self {
Self::FindObject(value.to_string())
}
}
impl From<std::string::FromUtf8Error> for Error {
fn from(value: std::string::FromUtf8Error) -> Self {
Self::NonUtf8Blob(value.to_string())
}
}
}