tms/
error.rs

1use std::{error::Error, fmt::Display};
2
3pub type Result<T> = error_stack::Result<T, TmsError>;
4
5#[derive(Debug)]
6pub enum TmsError {
7    GitError,
8    NonUtf8Path,
9    TuiError(String),
10    IoError,
11    ConfigError,
12}
13
14impl Display for TmsError {
15    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16        match self {
17            Self::ConfigError => write!(f, "Config Error"),
18            Self::GitError => write!(f, "Git Error"),
19            Self::NonUtf8Path => write!(f, "Non Utf-8 Path"),
20            Self::IoError => write!(f, "IO Error"),
21            Self::TuiError(inner) => write!(f, "TUI error: {inner}"),
22        }
23    }
24}
25
26impl Error for TmsError {}
27
28#[derive(Debug)]
29pub struct Suggestion(pub &'static str);
30impl Display for Suggestion {
31    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32        use crossterm::style::Stylize;
33        f.write_str(&format!("Suggestion: {}", self.0).green().bold().to_string())
34    }
35}