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)
| 519 | /// } |
| 520 | /// ``` |
| 521 | pub fn convert_remote_error(err: RemoteError, url: &str) -> CliError { |
| 522 | match err { |
| 523 | RemoteError::ConnectionFailed { .. } => CliError::RemoteError { |
| 524 | message: format!("Failed to connect: {}", err), |
| 525 | url: Some(url.to_string()), |
| 526 | }, |
| 527 | RemoteError::AuthenticationFailed { .. } => CliError::AuthenticationFailed { |
| 528 | remote: url.to_string(), |
| 529 | }, |
| 530 | RemoteError::RepositoryNotFound { .. } => CliError::RemoteError { |
| 531 | message: "Repository not found on remote".to_string(), |
| 532 | url: Some(url.to_string()), |
| 533 | }, |
| 534 | RemoteError::ViewNotFound { view } => CliError::RemoteError { |
| 535 | message: format!("View '{}' not found on remote", view), |
| 536 | url: Some(url.to_string()), |
| 537 | }, |
| 538 | RemoteError::ChangeNotFound { hash } => CliError::ChangeNotFound { hash }, |
| 539 | RemoteError::TagNotFound { state } => CliError::RemoteError { |
| 540 | message: format!("Tag not found for state: {}", state), |
| 541 | url: Some(url.to_string()), |
| 542 | }, |
| 543 | RemoteError::MissingDependencies { |
| 544 | count, |
| 545 | missing_hashes, |
| 546 | } => CliError::MissingDependency { |
| 547 | change: "requested change".to_string(), |
| 548 | dependency: if missing_hashes.is_empty() { |
| 549 | format!("{} dependencies", count) |
| 550 | } else { |
| 551 | missing_hashes.join(", ") |
| 552 | }, |
| 553 | }, |
| 554 | RemoteError::StateMismatch { |
| 555 | remote_state, |
| 556 | requested_state, |
| 557 | } => CliError::Conflict { |
| 558 | description: format!( |
| 559 | "State mismatch: remote is at {}, requested {}", |
| 560 | remote_state, requested_state |
| 561 | ), |
| 562 | }, |
| 563 | RemoteError::Timeout { seconds } => CliError::RemoteError { |
| 564 | message: format!("Request timed out after {} seconds", seconds), |
| 565 | url: Some(url.to_string()), |
| 566 | }, |
| 567 | RemoteError::EmptyView { view } => CliError::RemoteError { |
| 568 | message: format!("View '{}' is empty", view), |
| 569 | url: Some(url.to_string()), |
| 570 | }, |
| 571 | _ => CliError::RemoteError { |
| 572 | message: err.to_string(), |
| 573 | url: Some(url.to_string()), |
| 574 | }, |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | // Formatting Utilities |