djvu_rs/error.rs
1//! Typed error hierarchy for the djvu-rs crate.
2//!
3//! This module provides:
4//! - [`DjVuError`] — the new top-level error type for phase-1+ code
5//! - [`IffError`] — errors from the new IFF container parser
6//! - [`BzzError`] — errors from the BZZ decompressor (phase 2a)
7//! - [`Jb2Error`] — errors from the JB2 bilevel image decoder
8//! - [`Iw44Error`] — errors from the IW44 wavelet image decoder
9//! - `LegacyError` — the original error type, kept for backward compatibility
10//! - `TextError` — errors from the text layer parser (phase 4, see `text` module)
11//! - `AnnotationError` — errors from the annotation parser (phase 4, see `annotation` module)
12
13#[cfg(not(feature = "std"))]
14use alloc::borrow::Cow;
15
16// ---- New phase-1 typed errors -----------------------------------------------
17
18/// Top-level error type for all DjVu decoding operations.
19#[derive(Debug, thiserror::Error)]
20#[non_exhaustive]
21pub enum DjVuError {
22 /// An error in the IFF container format.
23 #[error("IFF error: {0}")]
24 Iff(#[from] IffError),
25
26 /// A JB2 bitonal image decoding error.
27 #[error("JB2 error: {0}")]
28 Jb2(#[from] Jb2Error),
29
30 /// An IW44 wavelet image decoding error.
31 #[error("IW44 error: {0}")]
32 Iw44(#[from] Iw44Error),
33
34 /// A BZZ compression decoding error.
35 #[error("BZZ error: {0}")]
36 Bzz(#[from] BzzError),
37
38 /// A page number was not found in the document.
39 #[error("page {0} not found")]
40 PageNotFound(usize),
41
42 /// The document structure is invalid or unexpected.
43 #[error("invalid structure: {0}")]
44 InvalidStructure(&'static str),
45
46 /// A feature or format variant that is not yet supported.
47 #[error("unsupported: {0}")]
48 #[cfg(feature = "std")]
49 Unsupported(std::borrow::Cow<'static, str>),
50 /// A feature or format variant that is not yet supported.
51 #[error("unsupported: {0}")]
52 #[cfg(not(feature = "std"))]
53 Unsupported(Cow<'static, str>),
54
55 /// An I/O error (only available with the `std` feature).
56 #[cfg(feature = "std")]
57 #[error("I/O error: {0}")]
58 Io(#[from] std::io::Error),
59}
60
61pub use djvu_iff::IffError;
62
63pub use djvu_jb2::Jb2Error;
64
65pub use djvu_iw44::Iw44Error;
66
67pub use djvu_bzz::BzzError;
68
69// ---- Legacy error type (kept for backward compatibility) --------------------
70
71pub use djvu_iff::LegacyError;
72
73/// Alias for [`LegacyError`] at the path `crate::error::Error`.
74///
75/// This allows the legacy modules (document.rs, render.rs) which use
76/// `crate::error::Error` to continue resolving correctly.
77pub use LegacyError as Error;