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 rebase operation fails.
26    #[error("{0}")]
27    Rebase(String),
28
29    /// Raised when a hook execution fails.
30    #[error("{0}")]
31    Hook(String),
32
33    /// Raised when configuration operations fail.
34    #[error("{0}")]
35    Config(String),
36
37    /// I/O errors.
38    #[error("I/O error: {0}")]
39    Io(#[from] std::io::Error),
40
41    /// JSON serialization/deserialization errors.
42    #[error("JSON error: {0}")]
43    Json(#[from] serde_json::Error),
44}
45
46pub type Result<T> = std::result::Result<T, CwError>;