MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / convert_remote_error

Function convert_remote_error

atomic-cli/src/commands/push/helpers.rs:395–456  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

393///
394/// A `CliError` that can be displayed to the user.
395pub fn convert_remote_error(err: RemoteError, url: &str) -> CliError {
396 match err {
397 RemoteError::ConnectionFailed { .. } => CliError::RemoteError {
398 message: format!("Failed to connect: {}", err),
399 url: Some(url.to_string()),
400 },
401 RemoteError::AuthenticationFailed { .. } => CliError::AuthenticationFailed {
402 remote: url.to_string(),
403 },
404 // A 404 on a push is ambiguous. Private projects are deliberately
405 // masked: the server returns "not found" to anyone who isn't
406 // authenticated/authorized, so a missing project and a private one we
407 // can't see are indistinguishable on the wire. A push is a *write* that
408 // always requires auth, so the most likely cause is missing/expired
409 // credentials — not a genuinely-absent project/view. Say so, and point
410 // at the remedy, instead of the misleading "view not found".
411 RemoteError::RepositoryNotFound { .. } => CliError::RemoteError {
412 message: not_found_push_message("the project"),
413 url: Some(url.to_string()),
414 },
415 RemoteError::ViewNotFound { view } => CliError::RemoteError {
416 message: not_found_push_message(&format!("project/view '{}'", view)),
417 url: Some(url.to_string()),
418 },
419 RemoteError::ChangeNotFound { hash } => CliError::ChangeNotFound { hash },
420 RemoteError::MissingDependencies {
421 count,
422 missing_hashes,
423 } => CliError::MissingDependency {
424 change: "uploaded change".to_string(),
425 dependency: if missing_hashes.is_empty() {
426 format!("{} dependencies", count)
427 } else {
428 missing_hashes.join(", ")
429 },
430 },
431 RemoteError::StateMismatch {
432 remote_state,
433 requested_state,
434 } => CliError::Conflict {
435 description: format!(
436 "State mismatch: remote is at {}, requested {}",
437 remote_state, requested_state
438 ),
439 },
440 RemoteError::Timeout { seconds } => CliError::RemoteError {
441 message: format!("Request timed out after {} seconds", seconds),
442 url: Some(url.to_string()),
443 },
444 RemoteError::HttpError { status: 413, .. } => CliError::RemoteError {
445 message: "Change too large for server (413 Payload Too Large). \
446 The server's body size limit is too small. \
447 Ask the server admin to increase MAX_BODY_SIZE_MB."
448 .to_string(),
449 url: Some(url.to_string()),
450 },
451 _ => CliError::RemoteError {
452 message: err.to_string(),

Callers 8

run_asyncMethod · 0.70
require_manifest_supportFunction · 0.70
test_convert_auth_failedFunction · 0.70
test_convert_timeoutFunction · 0.70

Calls 2

not_found_push_messageFunction · 0.85
is_emptyMethod · 0.45

Tested by 6

test_convert_auth_failedFunction · 0.56
test_convert_timeoutFunction · 0.56