Skip to main content

pleiades_compression/
error.rs

1//! Compression error types.
2
3use core::fmt;
4
5/// Error categories for compression and artifact parsing.
6#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
8#[non_exhaustive]
9pub enum CompressionErrorKind {
10    /// The artifact magic header did not match.
11    InvalidMagic,
12    /// The artifact version is not supported.
13    UnsupportedVersion,
14    /// The checksum did not match the payload.
15    ChecksumMismatch,
16    /// The payload ended unexpectedly.
17    Truncated,
18    /// The artifact contents were malformed.
19    InvalidFormat,
20    /// The artifact declared an unsupported byte-order policy.
21    UnsupportedEndianPolicy,
22    /// The requested body was not present.
23    MissingBody,
24    /// A required channel was absent.
25    MissingChannel,
26    /// The requested instant was outside the available segments.
27    OutOfRangeInstant,
28    /// The instant used an unsupported time scale.
29    UnsupportedTimeScale,
30    /// A coefficient exceeded the supported integer quantization range.
31    QuantizationOverflow,
32}
33
34/// A structured compression error.
35#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
36#[derive(Clone, Debug, PartialEq, Eq)]
37pub struct CompressionError {
38    /// Error category.
39    pub kind: CompressionErrorKind,
40    /// Human-readable explanation.
41    pub message: String,
42}
43
44impl CompressionError {
45    /// Creates a new compression error.
46    pub fn new(kind: CompressionErrorKind, message: impl Into<String>) -> Self {
47        Self {
48            kind,
49            message: message.into(),
50        }
51    }
52}
53
54impl fmt::Display for CompressionError {
55    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56        write!(f, "{:?}: {}", self.kind, self.message)
57    }
58}
59
60impl std::error::Error for CompressionError {}