Skip to main content

git_worktree_manager/
error.rs

1/// Custom error types for git-worktree-manager.
2///
3/// Maps directly from the Python exception hierarchy in exceptions.py.
4use thiserror::Error;
5
6/// Base error type for all git-worktree-manager errors.
7#[derive(Error, Debug)]
8pub enum CwError {
9    /// Raised when a git operation fails.
10    #[error("{0}")]
11    Git(String),
12
13    /// Raised when a worktree cannot be found.
14    #[error("{0}")]
15    WorktreeNotFound(String),
16
17    /// Raised when a branch is invalid or in an unexpected state.
18    #[error("{0}")]
19    InvalidBranch(String),
20
21    /// Raised when a merge operation fails.
22    #[error("{0}")]
23    Merge(String),
24
25    /// Raised when a hook execution fails.
26    #[error("{0}")]
27    Hook(String),
28
29    /// Raised when configuration operations fail.
30    #[error("{0}")]
31    Config(String),
32
33    /// I/O errors.
34    #[error("I/O error: {0}")]
35    Io(#[from] std::io::Error),
36
37    /// JSON serialization/deserialization errors.
38    #[error("JSON error: {0}")]
39    Json(#[from] serde_json::Error),
40
41    /// Generic error with message.
42    #[error("{0}")]
43    Other(String),
44
45    /// Terminate the process with a specific non-zero exit code without
46    /// printing an error message. Used when the orchestrator has already
47    /// produced a summary.
48    #[error("")]
49    ExitCode(i32),
50}
51
52pub type Result<T> = std::result::Result<T, CwError>;