|
| 1 | +//! Errors related to the alignment, reading or writing of Atoms. |
| 2 | +
|
1 | 3 | use std::error::Error; |
2 | 4 | use std::fmt::{Display, Formatter}; |
3 | 5 | use urid::{Uri, URID}; |
@@ -136,6 +138,7 @@ pub enum AtomWriteError { |
136 | 138 | /// An user-friendly error message |
137 | 139 | error_message: &'static str, |
138 | 140 | }, |
| 141 | + /// An alignment error occurred when attempting to write to the underlying buffer. |
139 | 142 | AlignmentError(AlignmentError), |
140 | 143 | } |
141 | 144 |
|
@@ -182,27 +185,43 @@ impl Display for AtomWriteError { |
182 | 185 |
|
183 | 186 | impl Error for AtomWriteError {} |
184 | 187 |
|
| 188 | +/// Errors that can occur while writing atoms to a byte buffer. |
185 | 189 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] |
186 | 190 | #[non_exhaustive] |
187 | 191 | pub enum AtomReadError { |
| 192 | + /// The URID of the atom being currently read does not match the requested type's URID. |
188 | 193 | AtomUridMismatch { |
| 194 | + /// The full URI of the requested type |
189 | 195 | expected_uri: &'static Uri, |
| 196 | + /// The URID of the requested type |
190 | 197 | expected_urid: URID, |
| 198 | + /// The atom's actual URID |
191 | 199 | found_urid: URID, |
192 | 200 | }, |
| 201 | + /// The URID of the atom being currently read is not actually a valid URID (e.g. zero). |
193 | 202 | InvalidUrid { |
| 203 | + /// The full URI of the requested type |
194 | 204 | expected_uri: &'static Uri, |
| 205 | + /// The URID of the requested type |
195 | 206 | expected_urid: URID, |
| 207 | + /// The value found in the Atom's URID header. |
196 | 208 | found_urid: u32, |
197 | 209 | }, |
| 210 | + /// A read operation tried to occur outside of the buffer's bounds |
198 | 211 | ReadingOutOfBounds { |
| 212 | + /// The amount of available bytes in the buffer |
199 | 213 | available: usize, |
| 214 | + /// The requested amount of bytes |
200 | 215 | requested: usize, |
201 | 216 | }, |
| 217 | + /// The read Atom value was invalid for the given Atom type. |
202 | 218 | InvalidAtomValue { |
| 219 | + /// The Atom type being read |
203 | 220 | reading_type_uri: &'static Uri, |
| 221 | + /// The Atom-specific error message |
204 | 222 | error_message: &'static str, |
205 | 223 | }, |
| 224 | + /// An alignment error curred when trying to read from the underlying buffer. |
206 | 225 | AlignmentError(AlignmentError), |
207 | 226 | } |
208 | 227 |
|
@@ -255,9 +274,12 @@ impl Display for AtomReadError { |
255 | 274 |
|
256 | 275 | impl Error for AtomReadError {} |
257 | 276 |
|
| 277 | +/// The global atom error type, that encompasses both read and write errors, for convenience. |
258 | 278 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] |
259 | 279 | pub enum AtomError { |
| 280 | + /// An error occurred when trying to read an atom from a buffer. |
260 | 281 | ReadError(AtomReadError), |
| 282 | + /// An error occurred when trying to write an atom into a buffer. |
261 | 283 | WriteError(AtomWriteError), |
262 | 284 | } |
263 | 285 |
|
|
0 commit comments