//! Errors of the Git backend. /// Why a Git operation failed. #[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)] pub enum VcsError { /// No usable `git` was found: the setting names a missing file, or /// `git` is not on `PATH`. #[error("git was not found ({0})")] NotFound(String), /// The installed git is older than [`crate::MIN_VERSION`]. #[error("git {found} is too old; Lutra needs git {min} or newer")] TooOld { /// The version that was found. found: String, /// The minimum version. min: String, }, /// `git` could not be started. #[error("git could not be started: {0}")] Spawn(String), /// git did not finish within the timeout and was stopped. #[error("git did not finish within {seconds} s and was stopped")] Timeout { /// The timeout in seconds. seconds: u64, }, /// git wrote more than the output cap. #[error("git's output is larger than {limit} bytes")] TooLarge { /// The cap in bytes. limit: usize, }, /// git refused or failed; the message is git's own (capped). #[error("{0}")] Git(String), /// git's output could not be understood. #[error("unexpected output from git: {0}")] BadOutput(String), /// A path from the caller is empty, absolute, leaves the project or /// holds a character git cannot take. #[error("invalid path: {0}")] InvalidPath(String), /// A branch name or revision from the caller is not valid. #[error("invalid branch name: {0}")] InvalidName(String), /// A commit message is empty. #[error("the commit message is empty")] EmptyMessage, /// The call was cancelled and git was stopped. #[error("the Git operation was cancelled")] Cancelled, /// A remote URL or clone target from the caller is not valid. #[error("{0}")] InvalidInput(String), } impl VcsError { /// Whether the error is the caller's fault (bad path, name or message) /// rather than a failure of git. pub fn is_invalid_input(&self) -> bool { matches!( self, Self::InvalidPath(_) | Self::InvalidName(_) | Self::EmptyMessage | Self::InvalidInput(_) ) } }