#[derive(Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum YencError {
NoHeader,
InvalidHeader { field: String },
CrcMismatch { expected: u32, actual: u32 },
UnexpectedEof,
SizeMismatch {
expected: u64,
actual: u64,
},
}
impl std::fmt::Display for YencError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
YencError::NoHeader => write!(
f,
"no '=ybegin' line found — input is not a yEnc article or the header was stripped"
),
YencError::InvalidHeader { field } => write!(
f,
"yEnc header missing or invalid required field '{}' — \
check that the full article header is present and well-formed",
field
),
YencError::CrcMismatch { expected, actual } => write!(
f,
"CRC32 mismatch: header claimed {:#010x}, decoded bytes hashed to {:#010x} — \
the article data is corrupt; re-fetch and retry",
expected, actual
),
YencError::UnexpectedEof => write!(
f,
"no '=yend' line found — article was truncated; re-fetch the article"
),
YencError::SizeMismatch { expected, actual } => write!(
f,
"size mismatch: =yend size={expected} but decoded {actual} bytes — \
the article data is corrupt or truncated; re-fetch and retry"
),
}
}
}
impl std::error::Error for YencError {}