1use std::fmt;
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Debug, Clone, PartialEq)]
6pub enum Error {
7 Truncated {
8 offset: usize,
9 needed: usize,
10 available: usize,
11 },
12 InvalidMagic,
13 UnsupportedVersion(u32),
14 UnsupportedFeature(&'static str),
15 InvalidHeader(&'static str),
16 InvalidBlob(String),
17 ChecksumMismatch {
18 expected: u32,
19 actual: u32,
20 },
21}
22
23impl fmt::Display for Error {
24 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25 match self {
26 Self::Truncated {
27 offset,
28 needed,
29 available,
30 } => write!(
31 f,
32 "truncated input at offset {offset}: need {needed} bytes, have {available}"
33 ),
34 Self::InvalidMagic => write!(f, "invalid LERC magic"),
35 Self::UnsupportedVersion(version) => {
36 write!(f, "unsupported LERC version {version}")
37 }
38 Self::UnsupportedFeature(feature) => write!(f, "unsupported LERC feature: {feature}"),
39 Self::InvalidHeader(reason) => write!(f, "invalid LERC header: {reason}"),
40 Self::InvalidBlob(reason) => write!(f, "invalid LERC blob: {reason}"),
41 Self::ChecksumMismatch { expected, actual } => {
42 write!(
43 f,
44 "LERC checksum mismatch: expected {expected:#010x}, got {actual:#010x}"
45 )
46 }
47 }
48 }
49}
50
51impl std::error::Error for Error {}