#[cfg(not(feature = "std"))]
use alloc::{borrow::Cow, string::String};
#[derive(Debug, thiserror::Error)]
pub enum DjVuError {
#[error("IFF error: {0}")]
Iff(#[from] IffError),
#[error("JB2 error: {0}")]
Jb2(#[from] Jb2Error),
#[error("IW44 error: {0}")]
Iw44(#[from] Iw44Error),
#[error("BZZ error: {0}")]
Bzz(#[from] BzzError),
#[error("page {0} not found")]
PageNotFound(usize),
#[error("invalid structure: {0}")]
InvalidStructure(&'static str),
#[error("unsupported: {0}")]
#[cfg(feature = "std")]
Unsupported(std::borrow::Cow<'static, str>),
#[error("unsupported: {0}")]
#[cfg(not(feature = "std"))]
Unsupported(Cow<'static, str>),
#[cfg(feature = "std")]
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
}
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
pub enum IffError {
#[error("input is too short to be a valid IFF file")]
TooShort,
#[error("bad magic bytes: expected AT&T, got {got:?}")]
BadMagic { got: [u8; 4] },
#[error("unknown FORM type: {id:?}")]
UnknownFormType { id: [u8; 4] },
#[error(
"chunk {:?} claims {} bytes but only {} are available",
id,
claimed,
available
)]
ChunkTooLong {
id: [u8; 4],
claimed: u32,
available: usize,
},
#[error("unexpected end of input (truncated IFF data)")]
Truncated,
}
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
pub enum Jb2Error {
#[error("JB2 stream is truncated")]
Truncated,
#[error("JB2: bad flag bit in header")]
BadHeaderFlag,
#[error("JB2: inherited dict length exceeds shared dict size")]
InheritedDictTooLarge,
#[error("JB2: stream requires shared dict but none provided")]
MissingSharedDict,
#[error("JB2: image dimensions too large")]
ImageTooLarge,
#[error("JB2: dict reference with empty dict")]
EmptyDictReference,
#[error("JB2: decoded symbol index out of dictionary range")]
InvalidSymbolIndex,
#[error("JB2: unknown record type")]
UnknownRecordType,
#[error("JB2: unexpected record type in dict stream")]
UnexpectedDictRecordType,
#[error("JB2: insufficient data to initialize ZP coder")]
ZpInitFailed,
#[error("JB2: record count exceeds safety limit")]
TooManyRecords,
}
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
pub enum Iw44Error {
#[error("IW44 stream is truncated")]
Truncated,
#[error("IW44 stream contains invalid data")]
Invalid,
#[error("IW44 chunk is too short")]
ChunkTooShort,
#[error("IW44 first chunk header too short (need ≥ 9 bytes)")]
HeaderTooShort,
#[error("IW44 image has zero dimension")]
ZeroDimension,
#[error("IW44 image dimensions too large")]
ImageTooLarge,
#[error("IW44 subsequent chunk received before first chunk")]
MissingFirstChunk,
#[error("IW44 subsample must be >= 1")]
InvalidSubsample,
#[error("IW44 codec not yet initialized")]
MissingCodec,
#[error("IW44 ZP coder stream too short")]
ZpTooShort,
}
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
pub enum BzzError {
#[error("BZZ input is too short")]
TooShort,
#[error("BZZ stream contains an invalid block size")]
InvalidBlockSize,
#[error("BZZ stream contains an invalid BWT index")]
InvalidBwtIndex,
#[error("ZP coder error in BZZ stream")]
ZpError,
#[error("BZZ block is missing the end-of-block marker")]
MissingMarker,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum LegacyError {
UnexpectedEof,
InvalidMagic,
InvalidLength,
MissingChunk(&'static str),
Unsupported(&'static str),
FormatError(String),
}
impl core::fmt::Display for LegacyError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
LegacyError::UnexpectedEof => write!(f, "unexpected end of input"),
LegacyError::InvalidMagic => write!(f, "invalid magic number"),
LegacyError::InvalidLength => write!(f, "invalid length"),
LegacyError::MissingChunk(id) => write!(f, "missing required chunk: {}", id),
LegacyError::Unsupported(msg) => write!(f, "unsupported: {}", msg),
LegacyError::FormatError(msg) => write!(f, "format error: {}", msg),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for LegacyError {}
pub use LegacyError as Error;