eggress_pproxy_compat/
issues.rs1use crate::diagnostics::{DiagnosticCode, StructuredDiagnostic};
16use crate::warnings::{CompatWarning, UnsupportedFeature};
17
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub enum IssueSeverity {
21 Warning,
23 Unsupported,
25 Info,
27}
28
29impl std::fmt::Display for IssueSeverity {
30 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31 match self {
32 Self::Warning => f.write_str("warning"),
33 Self::Unsupported => f.write_str("unsupported"),
34 Self::Info => f.write_str("info"),
35 }
36 }
37}
38
39#[derive(Debug, Clone, PartialEq)]
41pub struct CompatIssue {
42 pub severity: IssueSeverity,
44 pub code: DiagnosticCode,
46 pub category: Option<&'static str>,
48 pub feature: Option<&'static str>,
50 pub feature_id: Option<String>,
52 pub tier: Option<String>,
55 pub message: String,
57 pub suggestion: Option<String>,
59}
60
61impl CompatIssue {
62 pub fn warning(warn: CompatWarning) -> Self {
68 let category = warn.category;
69 let diag = StructuredDiagnostic::from(&warn);
70 Self {
71 severity: IssueSeverity::Warning,
72 code: diag.code,
73 category: Some(category),
74 feature: None,
75 feature_id: diag.feature_id,
76 tier: diag.tier,
77 message: diag.message,
78 suggestion: diag.suggestion,
79 }
80 }
81
82 pub fn unsupported(item: UnsupportedFeature) -> Self {
85 let feature = item.feature;
86 let code = crate::diagnostics::classify_unsupported_feature_code(feature);
87 let tier = crate::diagnostics::classify_unsupported_feature_tier(feature);
88 let diag = StructuredDiagnostic::from(crate::error::CompatError::unsupported(
91 feature,
92 item.detail.clone(),
93 ));
94 debug_assert_eq!(diag.code, code);
95 Self {
96 severity: IssueSeverity::Unsupported,
97 code,
98 category: None,
99 feature: Some(feature),
100 feature_id: Some(feature.to_string()),
101 tier: Some(tier.to_string()),
102 message: diag.message,
103 suggestion: diag.suggestion,
104 }
105 }
106
107 pub fn warning_category(category: &'static str, message: impl Into<String>) -> Self {
109 Self::warning(CompatWarning {
110 category,
111 message: message.into(),
112 })
113 }
114
115 pub fn unsupported_feature(feature: &'static str, detail: impl Into<String>) -> Self {
117 Self::unsupported(UnsupportedFeature {
118 feature,
119 detail: detail.into(),
120 })
121 }
122
123 pub fn to_warning(&self) -> Option<CompatWarning> {
125 match self.severity {
126 IssueSeverity::Warning => Some(CompatWarning {
127 category: self.category.unwrap_or("general"),
128 message: self.message.clone(),
129 }),
130 IssueSeverity::Unsupported | IssueSeverity::Info => None,
131 }
132 }
133
134 pub fn to_unsupported(&self) -> Option<UnsupportedFeature> {
136 match self.severity {
137 IssueSeverity::Unsupported => Some(UnsupportedFeature {
138 feature: self.feature.unwrap_or("unknown"),
139 detail: self.message.clone(),
140 }),
141 IssueSeverity::Warning | IssueSeverity::Info => None,
142 }
143 }
144
145 pub fn to_diagnostic(&self) -> StructuredDiagnostic {
147 StructuredDiagnostic {
148 code: self.code,
149 feature_id: self.feature_id.clone(),
150 tier: self.tier.clone(),
151 message: self.message.clone(),
152 suggestion: self.suggestion.clone(),
153 }
154 }
155}
156
157impl std::fmt::Display for CompatIssue {
158 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
159 write!(f, "[{}:{}] {}", self.severity, self.code, self.message)?;
160 if let Some(ref tier) = self.tier {
161 write!(f, " (tier: {})", tier)?;
162 }
163 if let Some(ref suggestion) = self.suggestion {
164 write!(f, " — suggestion: {}", suggestion)?;
165 }
166 Ok(())
167 }
168}