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)
| 5322 | /// body's composed message) back to the exact CLI error the local body |
| 5323 | /// raised, printing the same spinner-stage line. |
| 5324 | fn 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 | |
| 5378 | use std::collections::HashMap; |
| 5379 |