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}
11
12#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
13pub struct ScanDiagnostic {
14 pub severity: DiagnosticSeverity,
15 pub message: String,
16 #[serde(default, skip)]
17 pub is_timeout: bool,
18}
19
20impl ScanDiagnostic {
21 pub fn warning(message: impl Into<String>) -> Self {
22 Self {
23 severity: DiagnosticSeverity::Warning,
24 message: message.into(),
25 is_timeout: false,
26 }
27 }
28
29 pub fn error(message: impl Into<String>) -> Self {
30 Self {
31 severity: DiagnosticSeverity::Error,
32 message: message.into(),
33 is_timeout: false,
34 }
35 }
36
37 pub fn timeout(message: impl Into<String>) -> Self {
38 Self {
39 severity: DiagnosticSeverity::Error,
40 message: message.into(),
41 is_timeout: true,
42 }
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}