Convert a remote error to a CLI error. Maps the various remote error types to appropriate CLI error types with user-friendly messages and suggestions. # Arguments `err` - The remote error to convert `url` - The remote URL (for context in error messages) # Returns A `CliError` that can be displayed to the user. # Example ```rust,ignore let result = remote.get_state("main").await; if let Err(
(err: RemoteError, url: &str)
| 223 | /// } |
| 224 | /// ``` |
| 225 | pub fn convert_remote_error(err: RemoteError, url: &str) -> CliError { |
| 226 | match err { |
| 227 | RemoteError::ConnectionFailed { .. } => CliError::RemoteError { |
| 228 | message: format!("Failed to connect: {}", err), |
| 229 | url: Some(url.to_string()), |
| 230 | }, |
| 231 | RemoteError::AuthenticationFailed { .. } => CliError::AuthenticationFailed { |
| 232 | remote: url.to_string(), |
| 233 | }, |
| 234 | RemoteError::RepositoryNotFound { .. } => CliError::RemoteError { |
| 235 | message: "Repository not found on remote".to_string(), |
| 236 | url: Some(url.to_string()), |
| 237 | }, |
| 238 | RemoteError::ViewNotFound { view } => CliError::RemoteError { |
| 239 | message: format!("View '{}' not found on remote", view), |
| 240 | url: Some(url.to_string()), |
| 241 | }, |
| 242 | RemoteError::ChangeNotFound { hash } => CliError::ChangeNotFound { hash }, |
| 243 | RemoteError::TagNotFound { state } => CliError::RemoteError { |
| 244 | message: format!("Tag not found for state: {}", state), |
| 245 | url: Some(url.to_string()), |
| 246 | }, |
| 247 | RemoteError::MissingDependencies { |
| 248 | count, |
| 249 | missing_hashes, |
| 250 | } => CliError::MissingDependency { |
| 251 | change: "requested change".to_string(), |
| 252 | dependency: if missing_hashes.is_empty() { |
| 253 | format!("{} dependencies", count) |
| 254 | } else { |
| 255 | missing_hashes.join(", ") |
| 256 | }, |
| 257 | }, |
| 258 | RemoteError::StateMismatch { |
| 259 | remote_state, |
| 260 | requested_state, |
| 261 | } => CliError::Conflict { |
| 262 | description: format!( |
| 263 | "State mismatch: remote is at {}, requested {}", |
| 264 | remote_state, requested_state |
| 265 | ), |
| 266 | }, |
| 267 | RemoteError::Timeout { seconds } => CliError::RemoteError { |
| 268 | message: format!("Request timed out after {} seconds", seconds), |
| 269 | url: Some(url.to_string()), |
| 270 | }, |
| 271 | RemoteError::EmptyView { view } => CliError::RemoteError { |
| 272 | message: format!("View '{}' is empty", view), |
| 273 | url: Some(url.to_string()), |
| 274 | }, |
| 275 | _ => CliError::RemoteError { |
| 276 | message: err.to_string(), |
| 277 | url: Some(url.to_string()), |
| 278 | }, |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | // Display Helpers |