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

Function sync_error_map

atomic-cli/src/commands/rpc.rs:5324–5376  ·  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

5322/// body's composed message) back to the exact CLI error the local body
5323/// raised, printing the same spinner-stage line.
5324fn sync_error_map(error: CliError) -> CliError {
5325 let CliError::ServiceRefusal { message } = &error else {
5326 return error;
5327 };
5328 let Some(payload) = message.strip_prefix("atomic:REMOTE: ") else {
5329 return error;
5330 };
5331 let Ok(value) = serde_json::from_str::<serde_json::Value>(payload) else {
5332 return error;
5333 };
5334 let (Some(stage), Some(variant), Some(url), Some(text)) = (
5335 value.get("stage").and_then(|v| v.as_str()),
5336 value.get("variant").and_then(|v| v.as_str()),
5337 value.get("url").and_then(|v| v.as_str()),
5338 value.get("message").and_then(|v| v.as_str()),
5339 ) else {
5340 return error;
5341 };
5342 // The spinner-stage line the local body printed via finish_error.
5343 let stage_line = match stage {
5344 "connect" => Some("Failed to connect"),
5345 "advertise" => Some("Failed to fetch remote metadata"),
5346 "send" => Some("Push failed"),
5347 "verify" => Some("Push landed, but remote verification failed"),
5348 "verify-patch" => Some("Push landed, but remote union is incomplete"),
5349 "fetch" => Some("Failed to fetch remote view"),
5350 "fetch-missing" => Some("Remote view not found"),
5351 _ => None,
5352 };
5353 if let Some(line) = stage_line {
5354 eprintln!("✗ {line}");
5355 }
5356 match variant {
5357 "remote_error" => CliError::RemoteError {
5358 message: text.to_string(),
5359 url: Some(url.to_string()),
5360 },
5361 "authentication_failed" => CliError::AuthenticationFailed {
5362 remote: url.to_string(),
5363 },
5364 "change_not_found" => CliError::ChangeNotFound {
5365 hash: text.to_string(),
5366 },
5367 "missing_dependency" => CliError::MissingDependency {
5368 change: "uploaded change".to_string(),
5369 dependency: text.to_string(),
5370 },
5371 "conflict" => CliError::Conflict {
5372 description: text.to_string(),
5373 },
5374 _ => error,
5375 }
5376}
5377
5378use std::collections::HashMap;
5379

Callers 2

pushFunction · 0.85
pullFunction · 0.85

Calls 2

getMethod · 0.65
as_strMethod · 0.45

Tested by

no test coverage detected