fdm_toolkit/
err.rs

1use crate::chunk::{BlockGroup, Chunk};
2
3use core::fmt::{Formatter, Display, Result as FmtResult};
4use core::error::Error;
5
6
7
8
9
10#[non_exhaustive]
11#[derive(PartialEq, Clone, Debug, Eq)]
12pub enum ChunkReadError {
13	BrokenIdRunlengthPair(usize),
14	TooMuchData {
15		/// The last blockgroup in the sequence (as it was provided).
16		last_group:BlockGroup,
17		/// How many additional blocks
18		excess:usize
19	}
20}
21
22impl Display for ChunkReadError {
23	#[allow(deprecated)]
24	fn fmt(&self, f:&mut Formatter) -> FmtResult {
25		write!(f, "{}: {}", self.description(), match self {
26			Self::BrokenIdRunlengthPair(b) => format!("expected an even number of bytes, but found an odd amount ({b})"),
27			Self::TooMuchData {excess, ..} => format!("data for, at most, {} blocks was expected, but data for {} more block(s) was found", Chunk::HYPERVOLUME, excess)
28		})
29	}
30}
31
32impl Error for ChunkReadError {
33	fn description(&self) -> &'static str { "a chunk-reading error occurred" }
34}