Skip to main content

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)]
20pub enum DjVuError {
21    /// An error in the IFF container format.
22    #[error("IFF error: {0}")]
23    Iff(#[from] IffError),
24
25    /// A JB2 bitonal image decoding error.
26    #[error("JB2 error: {0}")]
27    Jb2(#[from] Jb2Error),
28
29    /// An IW44 wavelet image decoding error.
30    #[error("IW44 error: {0}")]
31    Iw44(#[from] Iw44Error),
32
33    /// A BZZ compression decoding error.
34    #[error("BZZ error: {0}")]
35    Bzz(#[from] BzzError),
36
37    /// A page number was not found in the document.
38    #[error("page {0} not found")]
39    PageNotFound(usize),
40
41    /// The document structure is invalid or unexpected.
42    #[error("invalid structure: {0}")]
43    InvalidStructure(&'static str),
44
45    /// A feature or format variant that is not yet supported.
46    #[error("unsupported: {0}")]
47    #[cfg(feature = "std")]
48    Unsupported(std::borrow::Cow<'static, str>),
49    /// A feature or format variant that is not yet supported.
50    #[error("unsupported: {0}")]
51    #[cfg(not(feature = "std"))]
52    Unsupported(Cow<'static, str>),
53
54    /// An I/O error (only available with the `std` feature).
55    #[cfg(feature = "std")]
56    #[error("I/O error: {0}")]
57    Io(#[from] std::io::Error),
58}
59
60pub use djvu_iff::IffError;
61
62pub use djvu_jb2::Jb2Error;
63
64pub use djvu_iw44::Iw44Error;
65
66pub use djvu_bzz::BzzError;
67
68// ---- Legacy error type (kept for backward compatibility) --------------------
69
70pub use djvu_iff::LegacyError;
71
72/// Alias for [`LegacyError`] at the path `crate::error::Error`.
73///
74/// This allows the legacy modules (document.rs, render.rs) which use
75/// `crate::error::Error` to continue resolving correctly.
76pub use LegacyError as Error;