Skip to main content

graphviz_pure_core/
error.rs

1use thiserror::Error;
2
3/// Unified error type for `graphviz-pure` replacing C Graphviz's `graphviz_exit()` and `agerr()`.
4#[derive(Debug, Error, Clone, PartialEq)]
5pub enum GraphvizError {
6    /// A DOT syntax error. `message` is worded as cgraph's `aagerror` (`lib/cgraph/scan.l`),
7    /// e.g. `syntax error in line 3 near ';'`, and `line` is the line it reports (cgraph's
8    /// `int line_num`).
9    #[error("{message}")]
10    SyntaxError {
11        line: i32,
12        col: usize,
13        message: String,
14        /// The file name set by a `# N "file"` line directive, which C reports instead of
15        /// the input's name.
16        file: Option<String>,
17    },
18
19    #[error("Unsupported layout engine: '{0}'")]
20    UnsupportedEngine(String),
21
22    #[error("Unsupported output format: '{0}'")]
23    UnsupportedFormat(String),
24
25    #[error("Layout computation error in {stage}: {message}")]
26    LayoutError {
27        stage: &'static str,
28        message: String,
29    },
30
31    #[error("Invalid attribute '{attr}': {message}")]
32    AttributeError { attr: String, message: String },
33
34    #[error("Rendering error: {0}")]
35    RenderError(String),
36}
37
38pub type Result<T> = std::result::Result<T, GraphvizError>;