Skip to main content

openjph_core/
error.rs

1//! Error types for the OpenJPH-RS codec — port of the C++ exception model.
2//!
3//! The C++ library uses three severity levels (INFO / WARN / ERROR) with
4//! integer error codes.  This module maps that model onto a single
5//! [`OjphError`] enum backed by [`thiserror`].
6
7use thiserror::Error;
8
9/// Top-level error type returned by all fallible codec operations.
10#[derive(Error, Debug)]
11pub enum OjphError {
12    /// A codec-level error with a numeric code (matches the C++ error codes).
13    #[error("codec error (0x{code:08x}): {message}")]
14    Codec {
15        /// Numeric error code.
16        code: u32,
17        /// Human-readable description.
18        message: String,
19    },
20
21    /// Wraps a [`std::io::Error`].
22    #[error("I/O error: {0}")]
23    Io(#[from] std::io::Error),
24
25    /// An invalid parameter was supplied.
26    #[error("invalid parameter: {0}")]
27    InvalidParam(String),
28
29    /// The requested feature is not (yet) supported.
30    #[error("unsupported feature: {0}")]
31    Unsupported(String),
32
33    /// A memory allocation failed.
34    #[error("memory allocation failed")]
35    AllocationFailed,
36}
37
38/// Convenience alias used throughout the crate.
39pub type Result<T> = std::result::Result<T, OjphError>;