provenant/models/
diagnostic.rs1use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7pub enum DiagnosticSeverity {
8 Warning,
9 Error,
10 Timeout,
11}
12
13#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
14pub struct ScanDiagnostic {
15 pub severity: DiagnosticSeverity,
16 pub message: String,
17}
18
19impl ScanDiagnostic {
20 pub fn warning(message: impl Into<String>) -> Self {
21 Self {
22 severity: DiagnosticSeverity::Warning,
23 message: message.into(),
24 }
25 }
26
27 pub fn error(message: impl Into<String>) -> Self {
28 Self {
29 severity: DiagnosticSeverity::Error,
30 message: message.into(),
31 }
32 }
33
34 pub fn timeout(message: impl Into<String>) -> Self {
35 Self {
36 severity: DiagnosticSeverity::Timeout,
37 message: message.into(),
38 }
39 }
40
41 pub fn is_timeout(&self) -> bool {
42 self.severity == DiagnosticSeverity::Timeout
43 }
44}
45
46pub fn diagnostics_from_legacy_scan_errors(messages: &[String]) -> Vec<ScanDiagnostic> {
47 messages
48 .iter()
49 .cloned()
50 .map(|message| {
51 if is_legacy_warning_message(&message) {
52 ScanDiagnostic::warning(message)
53 } else {
54 ScanDiagnostic::error(message)
55 }
56 })
57 .collect()
58}
59
60pub fn is_legacy_warning_message(message: &str) -> bool {
61 let first_line = message.lines().next().unwrap_or(message).trim();
62 first_line.starts_with("Maven property ")
63 || first_line.starts_with("Skipping Maven template coordinates")
64 || first_line.starts_with("Circular include detected")
65}