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

81 lines
1.9 KiB
Rust

//
pub type Result<T> = core::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("lock")]
Lock,
#[error("File not found: {}", 0)]
NotFound(String),
#[error("Unable to parse file contents")]
ParseContent,
#[error("Unable to decode from base64")]
DecodeFromBase64,
#[error("Unable to decode from UTF-8")]
DecodeFromUtf8,
#[error("Unknown file encoding: {}", 0)]
UnknownEncoding(String),
#[error("Not a file: {}", 0)]
NotFile(String),
#[error("Unknown error (status: {})", 0)]
Unknown(String),
#[error("commit log: {0}")]
CommitLog(#[from] crate::commit::log::Error),
#[error("commit not found")]
CommitNotFound,
#[error("no tree in commit")]
NoTreeInCommit(String),
#[error("no .git-next.toml file found in repo")]
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,
}
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())
}
}
}