git-next/crates/core/src/git/file.rs
Paul Campbell 64293cfe6c
All checks were successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
Rust / build (map[name:stable]) (push) Successful in 8m8s
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
Rust / build (map[name:nightly]) (push) Successful in 13m25s
Release Please / Release-plz (push) Successful in 5m54s
ci/woodpecker/cron/cron-docker-builder Pipeline was successful
ci/woodpecker/cron/push-next Pipeline was successful
ci/woodpecker/cron/tag-created Pipeline was successful
refactor: replace to_string uses with a macro
2024-11-25 20:49:27 +00:00

84 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::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")]
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))]
use crate::s;
// 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(s!(value))
}
}
impl From<gix::object::commit::Error> for Error {
fn from(value: gix::object::commit::Error) -> Self {
Self::NoTreeInCommit(s!(value))
}
}
impl From<gix::object::find::existing::Error> for Error {
fn from(value: gix::object::find::existing::Error) -> Self {
Self::FindObject(s!(value))
}
}
impl From<std::string::FromUtf8Error> for Error {
fn from(value: std::string::FromUtf8Error) -> Self {
Self::NonUtf8Blob(s!(value))
}
}
}