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

Function sync_error_map

atomic-cli/src/commands/rpc.rs:5284–5336  ·  view source on GitHub ↗

Map the handler's structured sync error (stage + variant + the local body's composed message) back to the exact CLI error the local body raised, printing the same spinner-stage line.

(error: CliError)

Source from the content-addressed store, hash-verified

5282/// body's composed message) back to the exact CLI error the local body
5283/// raised, printing the same spinner-stage line.
5284fn sync_error_map(error: CliError) -> CliError {
5285 let CliError::ServiceRefusal { message } = &error else {
5286 return error;
5287 };
5288 let Some(payload) = message.strip_prefix("atomic:REMOTE: ") else {
5289 return error;
5290 };
5291 let Ok(value) = serde_json::from_str::<serde_json::Value>(payload) else {
5292 return error;
5293 };
5294 let (Some(stage), Some(variant), Some(url), Some(text)) = (
5295 value.get("stage").and_then(|v| v.as_str()),
5296 value.get("variant").and_then(|v| v.as_str()),
5297 value.get("url").and_then(|v| v.as_str()),
5298 value.get("message").and_then(|v| v.as_str()),
5299 ) else {
5300 return error;
5301 };
5302 // The spinner-stage line the local body printed via finish_error.
5303 let stage_line = match stage {
5304 "connect" => Some("Failed to connect"),
5305 "advertise" => Some("Failed to fetch remote metadata"),
5306 "send" => Some("Push failed"),
5307 "verify" => Some("Push landed, but remote verification failed"),
5308 "verify-patch" => Some("Push landed, but remote union is incomplete"),
5309 "fetch" => Some("Failed to fetch remote view"),
5310 "fetch-missing" => Some("Remote view not found"),
5311 _ => None,
5312 };
5313 if let Some(line) = stage_line {
5314 eprintln!("✗ {line}");
5315 }
5316 match variant {
5317 "remote_error" => CliError::RemoteError {
5318 message: text.to_string(),
5319 url: Some(url.to_string()),
5320 },
5321 "authentication_failed" => CliError::AuthenticationFailed {
5322 remote: url.to_string(),
5323 },
5324 "change_not_found" => CliError::ChangeNotFound {
5325 hash: text.to_string(),
5326 },
5327 "missing_dependency" => CliError::MissingDependency {
5328 change: "uploaded change".to_string(),
5329 dependency: text.to_string(),
5330 },
5331 "conflict" => CliError::Conflict {
5332 description: text.to_string(),
5333 },
5334 _ => error,
5335 }
5336}
5337
5338use std::collections::HashMap;
5339

Callers 2

pushFunction · 0.85
pullFunction · 0.85

Calls 2

getMethod · 0.65
as_strMethod · 0.45

Tested by

no test coverage detected