img_gen_renderer/error.rs
1use fontsource_downloader::error::FontSourceError;
2
3/// Errors produced while rendering images and loading renderer resources.
4#[derive(Debug, thiserror::Error)]
5pub enum ImgGenRendererError {
6 /// Wraps a specification validation error.
7 #[error(transparent)]
8 SpecError(#[from] img_gen_spec::ImgGenSpecError),
9
10 // --- Rendering and geometry. ---
11 /// Returned when a rendered shape exceeds safe raster bounds.
12 #[error("{shape} bounds are too large; width and height must be less than i32::MAX / 4")]
13 BoundsTooLarge {
14 /// The shape whose bounds were invalid.
15 shape: &'static str,
16 },
17
18 /// Returned when a shape path reports invalid bounds.
19 #[error("{shape} path has invalid bounds")]
20 InvalidPathBounds {
21 /// The shape whose path bounds were invalid.
22 shape: &'static str,
23 },
24
25 /// Returned when pixmap allocation fails for a rendered shape.
26 #[error("Failed to allocate pixmap for {shape} ({width}x{height})")]
27 PixmapAllocationFailed {
28 /// The shape being rasterized.
29 shape: &'static str,
30 /// The requested pixmap width.
31 width: u32,
32 /// The requested pixmap height.
33 height: u32,
34 },
35
36 /// Returned when an intermediate raster buffer cannot be converted to RGBA pixels.
37 #[error("Failed to convert raster buffer to RGBA for {shape} ({width}x{height})")]
38 RasterBufferConversionFailed {
39 /// The shape being rasterized.
40 shape: &'static str,
41 /// The raster buffer width.
42 width: u32,
43 /// The raster buffer height.
44 height: u32,
45 },
46
47 // --- Image IO. ---
48 /// Returned when an image cannot be written to disk.
49 #[error("Failed to save image to '{path}'")]
50 SaveImageFailed {
51 /// The output path that failed.
52 path: String,
53 #[source]
54 /// The underlying image-encoding error.
55 source: image::ImageError,
56 },
57
58 /// Returned when image bytes cannot be collected from the pixel buffer.
59 #[error("Failed to collect image bytes from pixel buffer")]
60 CollectImageBytesFailed {
61 #[source]
62 /// The underlying I/O error.
63 source: std::io::Error,
64 },
65
66 /// Returned when an input image file cannot be opened.
67 #[error("Failed to open image '{path}'")]
68 OpenImageFailed {
69 /// The image path that failed.
70 path: String,
71 #[source]
72 /// The underlying I/O error.
73 source: std::io::Error,
74 },
75
76 /// Returned when an input image file cannot be decoded.
77 #[error("Failed to decode image '{path}'")]
78 DecodeImageFailed {
79 /// The image path that failed.
80 path: String,
81 #[source]
82 /// The underlying decoder error.
83 source: image::ImageError,
84 },
85
86 /// Returned when an SVG file cannot be read from disk.
87 #[error("Failed to read SVG file '{path}'")]
88 ReadSvgFailed {
89 /// The SVG path/name that failed.
90 path: String,
91 #[source]
92 /// The underlying I/O error.
93 source: std::io::Error,
94 },
95
96 /// Returned when SVG parsing fails after the file is read.
97 #[error("Failed to parse SVG file '{path}'")]
98 ParseSvgFailed {
99 /// The SVG path/name that failed.
100 path: String,
101 #[source]
102 /// The underlying SVG parser error.
103 source: resvg::usvg::Error,
104 },
105
106 /// Returned when SVG XML parsing fails.
107 #[error("Failed to parse SVG XML in '{path}'")]
108 ParseSvgXmlFailed {
109 /// The SVG path/name that failed.
110 path: String,
111 #[source]
112 /// The underlying XML parser error.
113 source: resvg::usvg::roxmltree::Error,
114 },
115
116 /// Returned when an SVG scales down to zero pixels.
117 #[error("SVG '{path}' scaled to zero size")]
118 SvgScaledToZeroSize {
119 /// The SVG path/name that failed.
120 path: String,
121 },
122
123 /// Returned when a referenced image cannot be located.
124 #[error("Image not found: '{name}'")]
125 ImageNotFound {
126 /// The unresolved image name.
127 name: String,
128 },
129
130 // --- Typography and font loading. ---
131 /// Returned when a font file cannot be read.
132 #[error("Failed to read font file '{path}'")]
133 ReadFontFileFailed {
134 /// The font path that failed.
135 path: String,
136 #[source]
137 /// The underlying I/O error.
138 source: std::io::Error,
139 },
140
141 /// Returned when glyph shaping cannot obtain a font reference.
142 #[error("Failed to create font reference for glyph run")]
143 InvalidGlyphRunFontReference,
144
145 /// Wraps an error returned by the fontsource client.
146 #[error(transparent)]
147 FontSourceError(#[from] FontSourceError),
148}
149
150/// A specialized result type for renderer operations.
151pub type Result<T> = std::result::Result<T, ImgGenRendererError>;