use iris_abi::Tag;
#[derive(Clone, PartialEq, Eq, Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("this is not an iris container: it starts with {found:02x?} and not {expected:02x?}")]
NotAContainer {
found: Vec<u8>,
expected: Vec<u8>,
},
#[error("the container is truncated: {what} needs {needed} bytes and there are {available}")]
Truncated {
what: &'static str,
needed: u64,
available: u64,
},
#[error(
"this container is format {major}.{minor} and this build reads format {supported_major}.x"
)]
UnsupportedFormat {
major: u16,
minor: u16,
supported_major: u16,
},
#[error(
"a reserved field in the {what} is not zero, so this container uses something this build does not know about"
)]
Reserved {
what: &'static str,
},
#[error(
"section {id} covers bytes {offset}..{end} which is not inside the payload area of a {file_len} byte container"
)]
SectionOutOfBounds {
id: u32,
offset: u64,
end: u64,
file_len: u64,
},
#[error("section id {id} is used twice, so a reference to it is ambiguous")]
DuplicateSection {
id: u32,
},
#[error("the footer has no {0} record")]
MissingRecord(Tag),
#[error("the footer has more than one {0} record")]
RepeatedRecord(Tag),
#[error("the footer has a {tag} record at version {version}, which this build does not read")]
UnsupportedRecord {
tag: Tag,
version: u16,
},
#[error(
"the {what} digest does not match: the footer says {expected} and the bytes hash to {actual}"
)]
DigestMismatch {
what: String,
expected: String,
actual: String,
},
#[error("the footer is malformed: {0}")]
Footer(#[from] iris_abi::Error),
#[error(
"the container declares {needed} bytes for {what}, which does not fit in this build's address space"
)]
TooLarge {
what: &'static str,
needed: u64,
},
}
pub type Result<T> = core::result::Result<T, Error>;