use std::fmt;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
Truncated {
what: &'static str,
},
BadMagic {
got: [u8; 4],
},
UnsupportedBuild {
build_no: u32,
},
UnknownBaseType {
byte: u8,
},
TypeIndexOutOfRange {
index: u32,
count: u32,
},
BytecodeOutOfRange {
offset: u32,
length: u32,
},
Overflow {
what: &'static str,
},
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Truncated { what } => {
write!(f, "truncated input: {what} runs past end of buffer")
}
Self::BadMagic { got } => {
write!(f, "bad IFPS magic: expected `IFPS`, got {got:02x?}")
}
Self::UnsupportedBuild { build_no } => {
write!(f, "unsupported PSBuildNo: {build_no}")
}
Self::UnknownBaseType { byte } => {
write!(f, "unknown PascalScript BaseType: 0x{byte:02x}")
}
Self::TypeIndexOutOfRange { index, count } => {
write!(f, "type index {index} out of range (count={count})")
}
Self::BytecodeOutOfRange { offset, length } => {
write!(
f,
"bytecode pointer ({offset}, {length}) falls outside the input",
)
}
Self::Overflow { what } => write!(f, "integer overflow computing {what}"),
}
}
}
impl std::error::Error for Error {}