Skip to main content

systemprompt_runtime/startup_validation/
display.rs

1//! CLI rendering of [`StartupValidationReport`] errors and warnings.
2
3use systemprompt_logging::CliService;
4use systemprompt_logging::services::cli::BrandColors;
5use systemprompt_traits::{StartupValidationReport, ValidationReport};
6
7pub fn display_validation_report(report: &StartupValidationReport) {
8    CliService::output("");
9    CliService::output(&format!(
10        "{} {}",
11        BrandColors::stopped("✗"),
12        BrandColors::white_bold("Validation Failed")
13    ));
14
15    if let Some(ref path) = report.profile_path {
16        CliService::output(&format!(
17            "  {} {}",
18            BrandColors::dim("Profile:"),
19            BrandColors::highlight(&path.display().to_string())
20        ));
21    }
22
23    CliService::output("");
24    CliService::output(&format!(
25        "  {} error(s) found:",
26        BrandColors::stopped(&report.error_count().to_string())
27    ));
28
29    for domain in &report.domains {
30        display_domain_errors(domain);
31    }
32
33    for ext in &report.extensions {
34        display_extension_errors(ext);
35    }
36
37    CliService::output("");
38}
39
40fn display_domain_errors(domain: &ValidationReport) {
41    if !domain.has_errors() {
42        return;
43    }
44
45    CliService::output("");
46    CliService::output(&format!(
47        "  {} {}",
48        BrandColors::stopped("▸"),
49        BrandColors::white_bold(&domain.domain)
50    ));
51
52    for error in &domain.errors {
53        CliService::output(&format!(
54            "    {} {}",
55            BrandColors::dim("field:"),
56            error.field
57        ));
58        CliService::output(&format!(
59            "    {} {}",
60            BrandColors::dim("error:"),
61            error.message
62        ));
63        if let Some(ref path) = error.path {
64            CliService::output(&format!(
65                "    {} {}",
66                BrandColors::dim("path:"),
67                path.display()
68            ));
69        }
70        if let Some(ref suggestion) = error.suggestion {
71            CliService::output(&format!(
72                "    {} {}",
73                BrandColors::highlight("fix:"),
74                suggestion
75            ));
76        }
77    }
78}
79
80fn display_extension_errors(ext: &ValidationReport) {
81    if !ext.has_errors() {
82        return;
83    }
84
85    CliService::output("");
86    CliService::output(&format!(
87        "  {} {}",
88        BrandColors::stopped("▸"),
89        BrandColors::white_bold(&ext.domain)
90    ));
91
92    for error in &ext.errors {
93        CliService::output(&format!(
94            "    {} {}",
95            BrandColors::dim("field:"),
96            error.field
97        ));
98        CliService::output(&format!(
99            "    {} {}",
100            BrandColors::dim("error:"),
101            error.message
102        ));
103    }
104}
105
106pub fn display_validation_warnings(report: &StartupValidationReport) {
107    if report.warning_count() == 0 {
108        return;
109    }
110
111    CliService::output(&format!(
112        "  {} warning(s):",
113        BrandColors::starting(&report.warning_count().to_string())
114    ));
115
116    for domain in &report.domains {
117        for warning in &domain.warnings {
118            CliService::output("");
119            CliService::output(&format!(
120                "  {} [{}] {}",
121                BrandColors::starting("⚠"),
122                domain.domain,
123                warning.field
124            ));
125            CliService::output(&format!("    {}", warning.message));
126            if let Some(ref suggestion) = warning.suggestion {
127                CliService::output(&format!(
128                    "    {} {}",
129                    BrandColors::highlight("fix:"),
130                    suggestion
131                ));
132            }
133        }
134    }
135
136    CliService::output("");
137}