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