Skip to main content

rung_core/
error.rs

1//! Error types for rung-core.
2
3use std::path::PathBuf;
4
5/// Result type alias using [`Error`].
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Errors that can occur in rung-core operations.
9#[derive(Debug, thiserror::Error)]
10pub enum Error {
11    /// Not inside a Git repository.
12    #[error("not a git repository (or any parent up to mount point)")]
13    NotARepository,
14
15    /// The .git/rung directory doesn't exist (not initialized).
16    #[error("rung not initialized in this repository - run `rung init` first")]
17    NotInitialized,
18
19    /// Branch not found.
20    #[error("branch not found: {0}")]
21    BranchNotFound(String),
22
23    /// Invalid branch name.
24    #[error("invalid branch name '{name}': {reason}")]
25    InvalidBranchName {
26        /// The invalid name.
27        name: String,
28        /// Why the name is invalid.
29        reason: String,
30    },
31
32    /// Branch is not part of any stack.
33    #[error("branch '{0}' is not part of a rung stack")]
34    NotInStack(String),
35
36    /// Cyclic dependency detected in stack.
37    #[error("cyclic dependency detected: {0}")]
38    CyclicDependency(String),
39
40    /// Parent branch was deleted.
41    #[error("parent branch '{parent}' for '{branch}' no longer exists")]
42    OrphanedBranch { branch: String, parent: String },
43
44    /// Conflict detected during sync.
45    #[error("conflict in {file} while syncing {branch}")]
46    ConflictDetected { branch: String, file: String },
47
48    /// Rebase operation failed.
49    #[error("rebase failed for branch '{0}': {1}")]
50    RebaseFailed(String, String),
51
52    /// No backup found for undo.
53    #[error("no backup found - nothing to undo")]
54    NoBackupFound,
55
56    /// Sync already in progress.
57    #[error("sync already in progress - run `rung sync --continue` or `rung sync --abort`")]
58    SyncInProgress,
59
60    /// Sync operation failed.
61    #[error("sync failed: {0}")]
62    SyncFailed(String),
63
64    /// State file parsing error.
65    #[error("failed to parse {file}: {message}")]
66    StateParseError { file: PathBuf, message: String },
67
68    /// IO error.
69    #[error("io error: {0}")]
70    Io(#[from] std::io::Error),
71
72    /// JSON serialization error.
73    #[error("json error: {0}")]
74    Json(#[from] serde_json::Error),
75
76    /// TOML parsing error.
77    #[error("toml error: {0}")]
78    Toml(#[from] toml::de::Error),
79
80    /// Git operation error.
81    #[error("git error: {0}")]
82    Git(#[from] rung_git::Error),
83
84    /// Absorb operation error.
85    #[error("absorb error: {0}")]
86    Absorb(String),
87}