Skip to main content

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    SessionNotFound(String),
13}
14
15impl Display for TmsError {
16    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17        match self {
18            Self::ConfigError => write!(f, "Config Error"),
19            Self::GitError => write!(f, "Git Error"),
20            Self::NonUtf8Path => write!(f, "Non Utf-8 Path"),
21            Self::IoError => write!(f, "IO Error"),
22            Self::TuiError(inner) => write!(f, "TUI error: {inner}"),
23            Self::SessionNotFound(inner) => write!(f, "Session {inner} not found"),
24        }
25    }
26}
27
28impl Error for TmsError {}
29
30#[derive(Debug)]
31pub struct Suggestion(pub &'static str);
32impl Display for Suggestion {
33    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34        use crossterm::style::Stylize;
35        f.write_str(&format!("Suggestion: {}", self.0).green().bold().to_string())
36    }
37}