oxabl_cache_format/
error.rs1use std::fmt;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum FormatError {
7 BadMagic,
9 UnsupportedVersion(u8),
11 UnknownFlags(u8),
13 NonZeroReserved,
15 Truncated,
17 TrailingBytes,
19 LimitExceeded(&'static str),
21 InvalidUtf8,
23 Invalid(&'static str),
25}
26
27impl fmt::Display for FormatError {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 match self {
30 Self::BadMagic => f.write_str("wrong magic"),
31 Self::UnsupportedVersion(v) => write!(f, "unsupported version {v}"),
32 Self::UnknownFlags(v) => write!(f, "unknown flag bits {v:#04x}"),
33 Self::NonZeroReserved => f.write_str("reserved field is not zero"),
34 Self::Truncated => f.write_str("truncated input"),
35 Self::TrailingBytes => f.write_str("trailing bytes"),
36 Self::LimitExceeded(what) => write!(f, "limit exceeded: {what}"),
37 Self::InvalidUtf8 => f.write_str("string is not valid UTF-8"),
38 Self::Invalid(what) => write!(f, "invalid: {what}"),
39 }
40 }
41}
42
43impl std::error::Error for FormatError {}
44
45pub type Result<T> = std::result::Result<T, FormatError>;