zpl_forge/
error.rs

1use thiserror::Error;
2
3/// Errors that can occur during ZPL parsing and rendering.
4#[derive(Debug, Error)]
5pub enum ZplError {
6    /// Error during the parsing phase (nom).
7    #[error("Parse error at line {line}: {message}")]
8    ParseError {
9        /// Line number where the error occurred.
10        line: usize,
11        /// Description of the parse failure.
12        message: String,
13    },
14
15    /// Error building instructions from commands.
16    #[error("Instruction builder error: {0}")]
17    InstructionError(String),
18
19    /// Error specific to a rendering backend (PNG, PDF, etc).
20    #[error("Rendering backend error: {0}")]
21    BackendError(String),
22
23    /// Error related to font loading or registration.
24    #[error("Font error: {0}")]
25    FontError(String),
26
27    /// Input ZPL was empty or only contained whitespace.
28    #[error("Empty or invalid ZPL input")]
29    EmptyInput,
30
31    /// Errors related to image decoding (Base64 or binary).
32    #[error("Image processing error: {0}")]
33    ImageError(String),
34
35    /// Security limit reached (e.g., OOM protection).
36    #[error("Security limit exceeded: {0}")]
37    SecurityLimitExceeded(String),
38
39    /// Generic unexpected error.
40    #[error("Unexpected error: {0}")]
41    Unexpected(String),
42}
43
44/// A specialized Result type for ZPL operations.
45pub type ZplResult<T> = Result<T, ZplError>;