1#[cfg(feature = "nostd")]
4use alloc::string::String;
5#[cfg(feature = "nostd")]
6use core::fmt;
7#[cfg(not(feature = "nostd"))]
8use std::string::String;
9
10#[cfg(not(feature = "nostd"))]
11use thiserror::Error;
12
13#[cfg_attr(not(feature = "nostd"), derive(Error))]
15#[derive(Debug)]
16pub enum RenderError {
17 #[cfg_attr(
19 not(feature = "nostd"),
20 error("Invalid dimensions: dimensions must be positive and non-zero")
21 )]
22 InvalidDimensions,
23
24 #[cfg_attr(
26 not(feature = "nostd"),
27 error("Invalid buffer size: expected {expected} bytes, got {actual}")
28 )]
29 InvalidBufferSize {
30 expected: usize,
32 actual: usize,
34 },
35
36 #[cfg_attr(not(feature = "nostd"), error("Failed to create pixmap"))]
38 InvalidPixmap,
39
40 #[cfg_attr(not(feature = "nostd"), error("No rendering backend available"))]
42 NoBackendAvailable,
43
44 #[cfg_attr(not(feature = "nostd"), error("Unsupported backend: {0}"))]
46 UnsupportedBackend(&'static str),
47
48 #[cfg_attr(not(feature = "nostd"), error("Backend initialization failed: {0}"))]
50 BackendInitFailed(String),
51
52 #[cfg_attr(not(feature = "nostd"), error("Backend error: {0}"))]
54 BackendError(String),
55
56 #[cfg_attr(not(feature = "nostd"), error("Pipeline error: {0}"))]
58 PipelineError(String),
59
60 #[cfg_attr(not(feature = "nostd"), error("Text shaping failed: {0}"))]
62 ShapingError(String),
63
64 #[cfg_attr(not(feature = "nostd"), error("Drawing failed: {0}"))]
66 DrawingError(String),
67
68 #[cfg_attr(not(feature = "nostd"), error("Invalid draw command: {0}"))]
70 InvalidDrawCommand(String),
71
72 #[cfg_attr(not(feature = "nostd"), error("Effect application failed: {0}"))]
74 EffectError(String),
75
76 #[cfg_attr(not(feature = "nostd"), error("Compositing failed: {0}"))]
78 CompositingError(String),
79
80 #[cfg_attr(not(feature = "nostd"), error("Font error: {0}"))]
82 FontError(String),
83
84 #[cfg_attr(not(feature = "nostd"), error("GPU error: {0}"))]
86 GpuError(String),
87
88 #[cfg(target_arch = "wasm32")]
90 #[cfg_attr(not(feature = "nostd"), error("WASM error: {0}"))]
91 WasmError(String),
92
93 #[cfg_attr(not(feature = "nostd"), error("Resource limit exceeded: {0}"))]
95 ResourceLimitExceeded(String),
96
97 #[cfg_attr(not(feature = "nostd"), error("Invalid script: {0}"))]
99 InvalidScript(String),
100
101 #[cfg_attr(not(feature = "nostd"), error("Parse error: {0}"))]
103 ParseError(String),
104
105 #[cfg_attr(not(feature = "nostd"), error("Invalid input: {0}"))]
107 InvalidInput(String),
108
109 #[cfg_attr(not(feature = "nostd"), error("Core error: {0}"))]
111 CoreError(#[cfg_attr(not(feature = "nostd"), from)] ass_core::utils::CoreError),
112
113 #[cfg_attr(not(feature = "nostd"), error("Initialization error: {0}"))]
115 InitializationError(String),
116
117 #[cfg_attr(not(feature = "nostd"), error("IO error: {0}"))]
119 IOError(String),
120
121 #[cfg_attr(not(feature = "nostd"), error("Invalid state: {0}"))]
123 InvalidState(String),
124
125 #[cfg_attr(not(feature = "nostd"), error("Unsupported operation: {0}"))]
127 UnsupportedOperation(String),
128}
129
130impl RenderError {
131 pub fn is_recoverable(&self) -> bool {
133 matches!(
134 self,
135 Self::ShapingError(_)
136 | Self::DrawingError(_)
137 | Self::EffectError(_)
138 | Self::FontError(_)
139 )
140 }
141
142 pub fn is_resource_error(&self) -> bool {
144 matches!(self, Self::FontError(_) | Self::ResourceLimitExceeded(_))
145 }
146}
147
148#[cfg(feature = "nostd")]
150impl fmt::Display for RenderError {
151 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
152 match self {
153 Self::InvalidDimensions => write!(
154 f,
155 "Invalid dimensions: dimensions must be positive and non-zero"
156 ),
157 Self::InvalidBufferSize { expected, actual } => {
158 write!(
159 f,
160 "Invalid buffer size: expected {expected} bytes, got {actual}"
161 )
162 }
163 Self::InvalidPixmap => write!(f, "Failed to create pixmap"),
164 Self::NoBackendAvailable => write!(f, "No rendering backend available"),
165 Self::UnsupportedBackend(s) => write!(f, "Unsupported backend: {s}"),
166 Self::BackendInitFailed(s) => write!(f, "Backend initialization failed: {s}"),
167 Self::BackendError(s) => write!(f, "Backend error: {s}"),
168 Self::PipelineError(s) => write!(f, "Pipeline error: {s}"),
169 Self::ShapingError(s) => write!(f, "Text shaping failed: {s}"),
170 Self::DrawingError(s) => write!(f, "Drawing failed: {s}"),
171 Self::InvalidDrawCommand(s) => write!(f, "Invalid draw command: {s}"),
172 Self::EffectError(s) => write!(f, "Effect application failed: {s}"),
173 Self::CompositingError(s) => write!(f, "Compositing failed: {s}"),
174 Self::FontError(s) => write!(f, "Font error: {s}"),
175 Self::GpuError(s) => write!(f, "GPU error: {s}"),
176 #[cfg(target_arch = "wasm32")]
177 Self::WasmError(s) => write!(f, "WASM error: {s}"),
178 Self::ResourceLimitExceeded(s) => write!(f, "Resource limit exceeded: {s}"),
179 Self::InvalidScript(s) => write!(f, "Invalid script: {s}"),
180 Self::ParseError(s) => write!(f, "Parse error: {s}"),
181 Self::InvalidInput(s) => write!(f, "Invalid input: {s}"),
182 Self::CoreError(e) => write!(f, "Core error: {e}"),
183 Self::InitializationError(s) => write!(f, "Initialization error: {s}"),
184 Self::IOError(s) => write!(f, "IO error: {s}"),
185 Self::InvalidState(s) => write!(f, "Invalid state: {s}"),
186 Self::UnsupportedOperation(s) => write!(f, "Unsupported operation: {s}"),
187 }
188 }
189}
190
191#[cfg(feature = "nostd")]
193impl core::error::Error for RenderError {}