Skip to main content

qr_code_styling/
error.rs

1//! Error types for QR code styling library.
2
3use thiserror::Error;
4
5/// Result type alias using QRError.
6pub type Result<T> = std::result::Result<T, QRError>;
7
8/// Errors that can occur during QR code generation and styling.
9#[derive(Error, Debug)]
10pub enum QRError {
11    /// No data provided for QR code generation.
12    #[error("No data provided for QR code")]
13    MissingData,
14
15    /// Data is too large to fit in the specified QR code version.
16    #[error("Data too large for QR code: data requires more capacity than available")]
17    DataTooLarge,
18
19    /// Invalid QR code version specified.
20    #[error("Invalid QR code version: {0}")]
21    InvalidVersion(u8),
22
23    /// Canvas dimensions are too small for the QR code.
24    #[error("Canvas dimensions too small: {width}x{height}")]
25    CanvasTooSmall { width: u32, height: u32 },
26
27    /// Invalid color format provided.
28    #[error("Invalid color format: {0}")]
29    InvalidColor(String),
30
31    /// Gradient must have at least one color stop.
32    #[error("Gradient must have at least one color stop")]
33    EmptyGradient,
34
35    /// Failed to load an image.
36    #[error("Failed to load image: {0}")]
37    ImageLoadError(String),
38
39    /// Failed to encode an image.
40    #[error("Failed to encode image: {0}")]
41    ImageEncodeError(String),
42
43    /// IO error occurred.
44    #[error("IO error: {0}")]
45    IoError(#[from] std::io::Error),
46
47    /// Image processing error.
48    #[error("Image processing error: {0}")]
49    ImageError(#[from] image::ImageError),
50
51    /// QR code generation error.
52    #[error("QR code generation failed: {0}")]
53    QRGenerationError(String),
54
55    /// SVG rendering error.
56    #[error("SVG rendering error: {0}")]
57    SvgError(String),
58}