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

Function convert_remote_error

atomic-cli/src/commands/push/helpers.rs:384–445  ·  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

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