rust: add custom error types with thiserror

Swadhin Biswas committed 7 months ago
eccddd0
1 parent a97d2bd
commit eccddd0
1 file changed
+24 -0
Showing 1 changed file+24-0
▼RUST/src/error.rs
+24-0
1
+use thiserror::Error;
2
+
3
+#[derive(Debug, Error)]
4
+pub enum GCCError {
5
+ #[error("GCC workspace already exists at {path}")]
6
+ AlreadyExists { path: String },
7
+
8
+ #[error("GCC workspace not found at {path}")]
9
+ NotFound { path: String },
10
+
11
+ #[error("Branch '{name}' already exists")]
12
+ BranchExists { name: String },
13
+
14
+ #[error("Branch '{name}' not found")]
15
+ BranchNotFound { name: String },
16
+
17
+ #[error("IO error: {0}")]
18
+ Io(#[from] std::io::Error),
19
+
20
+ #[error("YAML parse error: {0}")]
21
+ Yaml(#[from] serde_yaml::Error),
22
+}
23
+
24
+pub type Result<T> = std::result::Result<T, GCCError>;
0
25