kroki_rs/diagrams/
error.rs

1use thiserror::Error;
2
3/// Represents all possible errors that can occur during diagram generation.
4#[derive(Debug, Error)]
5pub enum DiagramError {
6    /// The input diagram source failed validation.
7    #[error("Validation failed: {0}")]
8    ValidationFailed(String),
9
10    /// The required underlying tool or binary was not found on the system.
11    #[error("Tool not found: '{0}'. Is it installed and in your PATH?")]
12    ToolNotFound(String),
13
14    /// Execution of the tool timed out.
15    #[error("'{tool}' timed out after {timeout_ms}ms (input: {bytes} bytes)")]
16    ExecutionTimeout {
17        tool: String,
18        timeout_ms: u64,
19        bytes: usize,
20    },
21
22    /// The tool process executed but returned a non-zero exit code or failed to yield expected output.
23    #[error("Process execution failed: {0}")]
24    ProcessFailed(String),
25
26    /// Base64 decoding, Zlib decompression, or UTF-8 conversion failed.
27    #[error("Failed to decode requested string: {0}")]
28    DecodeFailed(String),
29
30    /// The requested output format is not supported by this provider.
31    #[error("Format '{format}' is not supported by provider '{provider}'")]
32    UnsupportedFormat { format: String, provider: String },
33
34    /// Catch-all for IO or system-level IO errors during execution.
35    #[error("I/O error: {0}")]
36    Io(#[from] std::io::Error),
37
38    /// An unexpected error occurred.
39    #[error("Internal error: {0}")]
40    Internal(String),
41}
42
43/// A specialized Result type for diagram generation operations.
44pub type DiagramResult<T> = std::result::Result<T, DiagramError>;