CommonLibrary/Error/
CommonError.rs1use std::path::PathBuf;
7
8use serde::{Deserialize, Serialize};
9use thiserror::Error;
10
11#[derive(Error, Debug, Clone, Serialize, Deserialize)]
15pub enum CommonError {
16 #[error("FileSystem I/O error for '{Path}': {Description}")]
18 FileSystemIO { Path:PathBuf, Description:String },
19
20 #[error("Resource not found: {0}")]
21 FileSystemNotFound(PathBuf),
22
23 #[error("Permission denied for operation on '{Path}': {Reason}")]
24 FileSystemPermissionDenied { Path:PathBuf, Reason:String },
25
26 #[error("Resource already exists: {0}")]
27 FileSystemFileExists(PathBuf),
28
29 #[error("Path is not a directory: {0}")]
30 FileSystemNotADirectory(PathBuf),
31
32 #[error("Path is a directory (expected a file): {0}")]
33 FileSystemIsADirectory(PathBuf),
34
35 #[error("Configuration update error for key '{Key}': {Description}")]
37 ConfigurationUpdate { Key:String, Description:String },
38
39 #[error("Configuration load error: {Description}")]
40 ConfigurationLoad { Description:String },
41
42 #[error("Invalid argument '{ArgumentName}': {Reason}")]
44 InvalidArgument { ArgumentName:String, Reason:String },
45
46 #[error("Feature not implemented: {FeatureName}")]
47 NotImplemented { FeatureName:String },
48
49 #[error("Internal state access error (e.g., lock poisoned): {Context}")]
50 StateLockPoisoned { Context:String },
51
52 #[error("Inter-process communication error: {Description}")]
53 IPCError { Description:String },
54
55 #[error("Access denied: {Reason}")]
56 AccessDenied { Reason:String },
57
58 #[error("Command '{CommandIdentifier}' execution failed: {Reason}")]
60 CommandExecution { CommandIdentifier:String, Reason:String },
61
62 #[error("Command '{Identifier}' not found")]
63 CommandNotFound { Identifier:String },
64
65 #[error("Feature '{FeatureName}' is not available")]
66 FeatureNotAvailable { FeatureName:String },
67
68 #[error("Language provider registration failed for '{ProviderType}': {Reason}")]
70 ProviderRegistration { ProviderType:String, Reason:String },
71
72 #[error("Language provider '{ProviderIdentifier}' invocation failed: {Reason}")]
73 ProviderInvocation { ProviderIdentifier:String, Reason:String },
74
75 #[error("Test run '{RunIdentifier}' not found")]
77 TestRunNotFound { RunIdentifier:String },
78
79 #[error("Test controller '{ControllerIdentifier}' not found")]
80 TestControllerNotFound { ControllerIdentifier:String },
81
82 #[error("TreeView provider not found for view ID '{ViewIdentifier}'")]
84 TreeViewProviderNotFound { ViewIdentifier:String },
85
86 #[error("Webview '{Handle}' not found")]
87 WebviewNotFound { Handle:String },
88
89 #[error("External service '{ServiceName}' failed: {Description}")]
91 ExternalServiceError { ServiceName:String, Description:String },
92
93 #[error("Secret access for key '{Key}' failed: {Reason}")]
94 SecretsAccess { Key:String, Reason:String },
95
96 #[error("UserInterface interaction failed: {Reason}")]
97 UserInterfaceInteraction { Reason:String },
98
99 #[error("Serialization or Deserialization error: {Description}")]
100 SerializationError { Description:String },
101
102 #[error("An unknown internal error occurred: {Description}")]
104 Unknown { Description:String },
105}
106
107impl CommonError {
108 pub fn FromStandardIOError(IOError:std::io::Error, Path:PathBuf, OperationContext:&str) -> Self {
112 let Description = IOError.to_string();
113
114 match IOError.kind() {
115 std::io::ErrorKind::NotFound => CommonError::FileSystemNotFound(Path),
116
117 std::io::ErrorKind::PermissionDenied => {
118 CommonError::FileSystemPermissionDenied { Path, Reason:Description }
119 },
120
121 std::io::ErrorKind::AlreadyExists => CommonError::FileSystemFileExists(Path),
122
123 _ => {
124 CommonError::FileSystemIO {
125 Path,
126
127 Description:format!("Operation '{}' failed: {}", OperationContext, Description),
128 }
129 },
130 }
131 }
132}
133
134impl From<serde_json::Error> for CommonError {
136 fn from(SerdeError:serde_json::Error) -> Self {
137 CommonError::SerializationError { Description:SerdeError.to_string() }
138 }
139}
140
141impl From<tauri::Error> for CommonError {
144 fn from(TauriError:tauri::Error) -> Self { CommonError::UserInterfaceInteraction { Reason:TauriError.to_string() } }
145}