alpine_protocol_sdk/
preflight.rs1use crate::error::{AlpineSdkError, SdkErrorContext};
2
3fn describe_error(error: &AlpineSdkError) -> String {
4 if let Some(hint) = error.user_hint() {
5 hint.to_string()
6 } else {
7 error.to_string()
8 }
9}
10
11pub fn format_preflight_summary(errors: &[SdkErrorContext]) -> String {
12 if errors.is_empty() {
13 return "Preflight checks passed.".to_string();
14 }
15 let mut sentences = Vec::new();
16 for ctx in errors {
17 let mut sentence = describe_error(&ctx.error);
18 let mut meta = Vec::new();
19 if let Some(device_id) = ctx.device_id.as_ref() {
20 meta.push(format!("device_id {}", device_id));
21 }
22 if let Some(ip) = ctx.ip.as_ref() {
23 meta.push(format!("ip {}", ip));
24 }
25 if let Some(port) = ctx.port {
26 meta.push(format!("port {}", port));
27 }
28 if let Some(operation) = ctx.operation.as_ref() {
29 meta.push(format!("op {}", operation));
30 }
31 if !meta.is_empty() {
32 sentence.push_str(&format!(" ({})", meta.join(", ")));
33 }
34 sentences.push(sentence);
35 }
36 sentences.join(". ") + "."
37}