mermaid_cli/tui/state/
error.rs1use std::time::Instant;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum ErrorSeverity {
10 Info,
12 Warning,
14 Error,
16 Security,
18}
19
20impl ErrorSeverity {
21 pub fn display(&self) -> &str {
22 match self {
23 ErrorSeverity::Info => "INFO",
24 ErrorSeverity::Warning => "WARN",
25 ErrorSeverity::Error => "ERROR",
26 ErrorSeverity::Security => "SECURITY",
27 }
28 }
29}
30
31#[derive(Debug, Clone)]
33pub struct ErrorEntry {
34 pub timestamp: Instant,
35 pub severity: ErrorSeverity,
36 pub message: String,
37 pub context: Option<String>,
38}
39
40impl ErrorEntry {
41 pub fn new(severity: ErrorSeverity, message: String) -> Self {
42 Self {
43 timestamp: Instant::now(),
44 severity,
45 message,
46 context: None,
47 }
48 }
49
50 pub fn with_context(severity: ErrorSeverity, message: String, context: String) -> Self {
51 Self {
52 timestamp: Instant::now(),
53 severity,
54 message,
55 context: Some(context),
56 }
57 }
58
59 pub fn display(&self) -> String {
60 match &self.context {
61 Some(ctx) => format!("[{}] {} - {}", self.severity.display(), self.message, ctx),
62 None => format!("[{}] {}", self.severity.display(), self.message),
63 }
64 }
65}