Skip to main content

graphs_tui/
error.rs

1use std::fmt;
2
3/// Errors that can occur during mermaid parsing/rendering
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum MermaidError {
6    /// Empty input provided
7    EmptyInput,
8    /// Parse error at specific line
9    ParseError {
10        line: usize,
11        message: String,
12        suggestion: Option<String>,
13    },
14    /// Layout error (e.g., cycle detected)
15    LayoutError(String),
16}
17
18impl fmt::Display for MermaidError {
19    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20        match self {
21            MermaidError::EmptyInput => write!(f, "Empty input"),
22            MermaidError::ParseError {
23                line,
24                message,
25                suggestion,
26            } => {
27                write!(f, "Line {}: {}", line, message)?;
28                if let Some(sug) = suggestion {
29                    write!(f, " (Suggestion: {})", sug)?;
30                }
31                Ok(())
32            }
33            MermaidError::LayoutError(msg) => write!(f, "Layout error: {}", msg),
34        }
35    }
36}
37
38impl std::error::Error for MermaidError {}