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 OutputTooSmall {
13 needed: usize,
14 available: usize,
15 },
16 InvalidMagic,
17 UnsupportedVersion(u32),
18 UnsupportedFeature(&'static str),
19 InvalidHeader(&'static str),
20 InvalidArgument(String),
21 InvalidBlob(String),
22 ChecksumMismatch {
23 expected: u32,
24 actual: u32,
25 },
26}
27
28impl fmt::Display for Error {
29 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30 match self {
31 Self::Truncated {
32 offset,
33 needed,
34 available,
35 } => write!(
36 f,
37 "truncated input at offset {offset}: need {needed} bytes, have {available}"
38 ),
39 Self::OutputTooSmall { needed, available } => write!(
40 f,
41 "output buffer too small: need {needed} bytes, have {available}"
42 ),
43 Self::InvalidMagic => write!(f, "invalid LERC magic"),
44 Self::UnsupportedVersion(version) => {
45 write!(f, "unsupported LERC version {version}")
46 }
47 Self::UnsupportedFeature(feature) => write!(f, "unsupported LERC feature: {feature}"),
48 Self::InvalidHeader(reason) => write!(f, "invalid LERC header: {reason}"),
49 Self::InvalidArgument(reason) => write!(f, "invalid argument: {reason}"),
50 Self::InvalidBlob(reason) => write!(f, "invalid LERC blob: {reason}"),
51 Self::ChecksumMismatch { expected, actual } => {
52 write!(
53 f,
54 "LERC checksum mismatch: expected {expected:#010x}, got {actual:#010x}"
55 )
56 }
57 }
58 }
59}
60
61impl std::error::Error for Error {}