1#[derive(Debug, thiserror::Error)]
5pub enum FlameError {
6 #[error("I/O error: {0}")]
8 Io(#[from] std::io::Error),
9
10 #[error("Failed to load array '{name}': {source}")]
12 NpyLoad {
13 name: String,
14 source: ndarray_npy::ReadNpyError,
15 },
16
17 #[cfg(feature = "npz")]
19 #[error("Failed to load NPZ array '{name}': {source}")]
20 NpzLoad {
21 name: String,
22 source: ndarray_npy::ReadNpzError,
23 },
24
25 #[error("Shape mismatch for '{name}': expected {expected}, got {got}")]
27 ShapeMismatch {
28 name: String,
29 expected: String,
30 got: String,
31 },
32
33 #[error("Model directory error: {0}")]
35 ModelDir(String),
36
37 #[error("Invalid parameters: {0}")]
39 InvalidParams(String),
40
41 #[error("Export failed: {format} - {reason}")]
43 Export {
44 format: String,
46 reason: String,
48 },
49
50 #[error("Animation error at frame {frame}: {reason}")]
52 Animation {
53 frame: usize,
55 reason: String,
57 },
58
59 #[error("Landmark error for index {index}: {reason}")]
61 Landmark {
62 index: usize,
64 reason: String,
66 },
67
68 #[error("Expression transfer failed: {reason}")]
70 Transfer {
71 reason: String,
73 },
74
75 #[error("Numerical error: {reason}")]
77 Numerical {
78 reason: String,
80 },
81
82 #[error("Index out of bounds: {context} - index {index} >= {len}")]
84 IndexOutOfBounds {
85 context: String,
87 index: usize,
89 len: usize,
91 },
92
93 #[error("Failed to load safetensors from '{path}': {message}")]
95 SafeTensorsLoad {
96 path: std::path::PathBuf,
98 message: String,
100 },
101
102 #[error("Failed to save safetensors to '{path}': {message}")]
104 SafeTensorsSave {
105 path: std::path::PathBuf,
107 message: String,
109 },
110
111 #[error("Missing tensor '{name}' in safetensors file: {message}")]
113 SafeTensorsMissing {
114 name: String,
116 message: String,
118 },
119
120 #[error("Invalid dtype for tensor '{name}': expected {expected}, got {got}")]
122 SafeTensorsInvalidDtype {
123 name: String,
125 expected: String,
127 got: String,
129 },
130
131 #[error("I/O error for '{path}': {source}")]
133 IoError {
134 source: std::io::Error,
136 path: std::path::PathBuf,
138 },
139}
140
141impl FlameError {
142 #[must_use]
144 pub fn export(format: impl Into<String>, reason: impl Into<String>) -> Self {
145 Self::Export {
146 format: format.into(),
147 reason: reason.into(),
148 }
149 }
150
151 #[must_use]
153 pub fn animation(frame: usize, reason: impl Into<String>) -> Self {
154 Self::Animation {
155 frame,
156 reason: reason.into(),
157 }
158 }
159
160 #[must_use]
162 pub fn landmark(index: usize, reason: impl Into<String>) -> Self {
163 Self::Landmark {
164 index,
165 reason: reason.into(),
166 }
167 }
168
169 #[must_use]
171 pub fn transfer(reason: impl Into<String>) -> Self {
172 Self::Transfer {
173 reason: reason.into(),
174 }
175 }
176
177 #[must_use]
179 pub fn numerical(reason: impl Into<String>) -> Self {
180 Self::Numerical {
181 reason: reason.into(),
182 }
183 }
184
185 #[must_use]
187 pub fn index_out_of_bounds(context: impl Into<String>, index: usize, len: usize) -> Self {
188 Self::IndexOutOfBounds {
189 context: context.into(),
190 index,
191 len,
192 }
193 }
194}