1pub mod core;
3
4pub mod domain;
6
7pub mod adapters;
9
10pub mod commands;
12
13pub mod cli;
15
16#[cfg(test)]
18pub mod examples;
19
20#[derive(Debug)]
22pub enum GitXError {
23 GitCommand(String),
24 Io(std::io::Error),
25 Parse(String),
26 Dialog(String),
27 Join(String),
28 Other(String),
29}
30
31impl std::fmt::Display for GitXError {
32 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 match self {
34 GitXError::GitCommand(cmd) => write!(f, "Git command failed: {cmd}"),
35 GitXError::Io(err) => write!(f, "IO error: {err}"),
36 GitXError::Parse(msg) => write!(f, "Parse error: {msg}"),
37 GitXError::Dialog(msg) => write!(f, "Dialog error: {msg}"),
38 GitXError::Join(msg) => write!(f, "Join error: {msg}"),
39 GitXError::Other(msg) => write!(f, "{msg}"),
40 }
41 }
42}
43
44impl std::error::Error for GitXError {
45 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
46 match self {
47 GitXError::Io(err) => Some(err),
48 GitXError::GitCommand(_)
49 | GitXError::Parse(_)
50 | GitXError::Dialog(_)
51 | GitXError::Join(_)
52 | GitXError::Other(_) => None,
53 }
54 }
55}
56
57impl From<std::io::Error> for GitXError {
58 fn from(err: std::io::Error) -> Self {
59 GitXError::Io(err)
60 }
61}
62
63impl From<dialoguer::Error> for GitXError {
64 fn from(err: dialoguer::Error) -> Self {
65 GitXError::Dialog(err.to_string())
66 }
67}
68
69impl From<tokio::task::JoinError> for GitXError {
70 fn from(err: tokio::task::JoinError) -> Self {
71 GitXError::Join(err.to_string())
72 }
73}
74
75pub type Result<T> = std::result::Result<T, GitXError>;