Common/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("Command '{CommandIdentifier}' execution failed: {Reason}")]
57 CommandExecution { CommandIdentifier:String, Reason:String },
58
59 #[error("Command '{Identifier}' not found")]
60 CommandNotFound { Identifier:String },
61
62 #[error("Language provider registration failed for '{ProviderType}': {Reason}")]
64 ProviderRegistration { ProviderType:String, Reason:String },
65
66 #[error("Language provider '{ProviderIdentifier}' invocation failed: {Reason}")]
67 ProviderInvocation { ProviderIdentifier:String, Reason:String },
68
69 #[error("TreeView provider not found for view ID '{ViewIdentifier}'")]
71 TreeViewProviderNotFound { ViewIdentifier:String },
72
73 #[error("External service '{ServiceName}' failed: {Description}")]
75 ExternalServiceError { ServiceName:String, Description:String },
76
77 #[error("Secret access for key '{Key}' failed: {Reason}")]
78 SecretsAccess { Key:String, Reason:String },
79
80 #[error("UserInterface interaction failed: {Reason}")]
81 UserInterfaceInteraction { Reason:String },
82
83 #[error("Serialization or Deserialization error: {Description}")]
84 SerializationError { Description:String },
85
86 #[error("An unknown internal error occurred: {Description}")]
88 Unknown { Description:String },
89}
90
91impl CommonError {
92 pub fn FromStandardIOError(IOError:std::io::Error, Path:PathBuf, OperationContext:&str) -> Self {
96 let Description = IOError.to_string();
97
98 match IOError.kind() {
99 std::io::ErrorKind::NotFound => CommonError::FileSystemNotFound(Path),
100
101 std::io::ErrorKind::PermissionDenied => {
102 CommonError::FileSystemPermissionDenied { Path, Reason:Description }
103 },
104
105 std::io::ErrorKind::AlreadyExists => CommonError::FileSystemFileExists(Path),
106
107 _ => {
108 CommonError::FileSystemIO {
109 Path,
110
111 Description:format!("Operation '{}' failed: {}", OperationContext, Description),
112 }
113 },
114 }
115 }
116}
117
118impl From<serde_json::Error> for CommonError {
120 fn from(SerdeError:serde_json::Error) -> Self {
121 CommonError::SerializationError { Description:SerdeError.to_string() }
122 }
123}
124
125impl From<tauri::Error> for CommonError {
128 fn from(TauriError:tauri::Error) -> Self { CommonError::UserInterfaceInteraction { Reason:TauriError.to_string() } }
129}