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.
(err: RemoteError, url: &str)
| 436 | /// |
| 437 | /// A `CliError` that can be displayed to the user. |
| 438 | pub fn convert_remote_error(err: RemoteError, url: &str) -> CliError { |
| 439 | match err { |
| 440 | RemoteError::ConnectionFailed { .. } => CliError::RemoteError { |
| 441 | message: format!("Failed to connect: {}", err), |
| 442 | url: Some(url.to_string()), |
| 443 | }, |
| 444 | RemoteError::AuthenticationFailed { .. } => CliError::AuthenticationFailed { |
| 445 | remote: url.to_string(), |
| 446 | }, |
| 447 | // A 404 on a push is ambiguous. Private projects are deliberately |
| 448 | // masked: the server returns "not found" to anyone who isn't |
| 449 | // authenticated/authorized, so a missing project and a private one we |
| 450 | // can't see are indistinguishable on the wire. A push is a *write* that |
| 451 | // always requires auth, so the most likely cause is missing/expired |
| 452 | // credentials — not a genuinely-absent project/view. Say so, and point |
| 453 | // at the remedy, instead of the misleading "view not found". |
| 454 | RemoteError::RepositoryNotFound { .. } => CliError::RemoteError { |
| 455 | message: not_found_push_message("the project"), |
| 456 | url: Some(url.to_string()), |
| 457 | }, |
| 458 | RemoteError::ViewNotFound { view } => CliError::RemoteError { |
| 459 | message: not_found_push_message(&format!("project/view '{}'", view)), |
| 460 | url: Some(url.to_string()), |
| 461 | }, |
| 462 | RemoteError::ChangeNotFound { hash } => CliError::ChangeNotFound { hash }, |
| 463 | RemoteError::MissingDependencies { |
| 464 | count, |
| 465 | missing_hashes, |
| 466 | } => CliError::MissingDependency { |
| 467 | change: "uploaded change".to_string(), |
| 468 | dependency: if missing_hashes.is_empty() { |
| 469 | format!("{} dependencies", count) |
| 470 | } else { |
| 471 | missing_hashes.join(", ") |
| 472 | }, |
| 473 | }, |
| 474 | RemoteError::StateMismatch { |
| 475 | remote_state, |
| 476 | requested_state, |
| 477 | } => CliError::Conflict { |
| 478 | description: format!( |
| 479 | "State mismatch: remote is at {}, requested {}", |
| 480 | remote_state, requested_state |
| 481 | ), |
| 482 | }, |
| 483 | RemoteError::Timeout { seconds } => CliError::RemoteError { |
| 484 | message: format!("Request timed out after {} seconds", seconds), |
| 485 | url: Some(url.to_string()), |
| 486 | }, |
| 487 | RemoteError::HttpError { status: 413, .. } => CliError::RemoteError { |
| 488 | message: "Change too large for server (413 Payload Too Large). \ |
| 489 | The server's body size limit is too small. \ |
| 490 | Ask the server admin to increase MAX_BODY_SIZE_MB." |
| 491 | .to_string(), |
| 492 | url: Some(url.to_string()), |
| 493 | }, |
| 494 | _ => CliError::RemoteError { |
| 495 | message: err.to_string(), |