//! Error handling for the pager binary. use std::io; use rustik_diff::DecodeError; use rustik_highlight as syntax; use rustik_repo::RepoError; /// Binary error type. #[derive(Debug)] pub(super) enum Error { /// I/O failed. Io(io::Error), /// Git returned a failing exit status. Git(i32), /// Repository discovery or Git plumbing failed. Repo(RepoError), /// Diff parsing failed. Parse(DecodeError), /// Syntax highlighting setup failed. Highlight(syntax::Error), } impl From for Error { fn from(error: io::Error) -> Self { Self::Io(error) } } impl From for Error { fn from(error: DecodeError) -> Self { Self::Parse(error) } } impl From for Error { fn from(error: syntax::Error) -> Self { Self::Highlight(error) } } impl From for Error { fn from(error: RepoError) -> Self { Self::Repo(error) } } impl std::fmt::Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Io(error) => write!(f, "{error}"), Self::Git(code) => write!(f, "git diff exited with status {code}"), Self::Repo(error) => write!(f, "{error}"), Self::Parse(error) => write!(f, "{error}"), Self::Highlight(error) => write!(f, "{error}"), } } } impl std::error::Error for Error {}