Skip to main content

jj_ryu/
error.rs

1//! Error types for jj-ryu
2//!
3//! Uses thiserror for structured errors that can be mapped to HTTP status codes
4//! in future web server implementations.
5
6use thiserror::Error;
7
8/// Main error type for jj-ryu operations
9#[derive(Error, Debug)]
10pub enum Error {
11    /// Failed to load or interact with jj workspace
12    #[error("workspace error: {0}")]
13    Workspace(String),
14
15    /// Failed to parse jj output or data
16    #[error("parse error: {0}")]
17    Parse(String),
18
19    /// Bookmark not found in repository
20    #[error("bookmark '{0}' not found")]
21    BookmarkNotFound(String),
22
23    /// No stack found (working copy at trunk or no bookmarks)
24    #[error("{0}")]
25    NoStack(String),
26
27    /// No supported remotes (GitHub/GitLab) found
28    #[error("no supported remotes found (GitHub/GitLab)")]
29    NoSupportedRemotes,
30
31    /// Specified remote not found
32    #[error("remote '{0}' not found")]
33    RemoteNotFound(String),
34
35    /// Authentication failed
36    #[error("authentication failed: {0}")]
37    Auth(String),
38
39    /// GitHub API error
40    #[error("GitHub API error: {0}")]
41    GitHubApi(String),
42
43    /// GitLab API error
44    #[error("GitLab API error: {0}")]
45    GitLabApi(String),
46
47    /// Merge commit detected (cannot stack)
48    #[error("merge commit detected in bookmark '{0}' history - rebasing required")]
49    MergeCommitDetected(String),
50
51    /// Revset evaluation failed
52    #[error("revset error: {0}")]
53    Revset(String),
54
55    /// Git operation failed
56    #[error("git operation failed: {0}")]
57    Git(String),
58
59    /// Invalid configuration
60    #[error("invalid configuration: {0}")]
61    Config(String),
62
63    /// IO error
64    #[error("IO error: {0}")]
65    Io(#[from] std::io::Error),
66
67    /// HTTP request error
68    #[error("HTTP error: {0}")]
69    Http(#[from] reqwest::Error),
70
71    /// JSON serialization/deserialization error
72    #[error("JSON error: {0}")]
73    Json(#[from] serde_json::Error),
74
75    /// URL parsing error
76    #[error("URL parse error: {0}")]
77    UrlParse(#[from] url::ParseError),
78
79    /// Octocrab (GitHub) error
80    #[error("GitHub client error: {0}")]
81    Octocrab(#[from] octocrab::Error),
82
83    /// Platform API error (generic)
84    #[error("platform error: {0}")]
85    Platform(String),
86
87    /// Internal error (unexpected state)
88    #[error("internal error: {0}")]
89    Internal(String),
90
91    /// Scheduler detected a cycle in execution dependencies (indicates a bug)
92    #[error("scheduler cycle detected: {message}")]
93    SchedulerCycle {
94        /// Human-readable description
95        message: String,
96        /// Node names involved in the cycle (for debugging)
97        cycle_nodes: Vec<String>,
98    },
99
100    /// Invalid command-line argument
101    #[error("invalid argument: {0}")]
102    InvalidArgument(String),
103
104    /// Tracking state error
105    #[error("tracking error: {0}")]
106    Tracking(String),
107}
108
109/// Result type alias for jj-ryu operations
110pub type Result<T> = std::result::Result<T, Error>;