Skip to main content

serializer/machine/
types.rs

1//! Machine format error types
2
3use thiserror::Error;
4
5/// Result type for machine operations
6pub type Result<T> = std::result::Result<T, DxMachineError>;
7
8/// Machine format errors
9#[derive(Debug, Error)]
10pub enum DxMachineError {
11    /// Machine-format serialization failed.
12    #[error("Serialization error: {0}")]
13    Serialization(String),
14
15    /// Machine-format deserialization failed.
16    #[error("Deserialization error: {0}")]
17    Deserialization(String),
18
19    /// Compression failed before writing machine data.
20    #[error("Compression error: {0}")]
21    Compression(String),
22
23    /// Decompression failed while reading machine data.
24    #[error("Decompression error: {0}")]
25    Decompression(String),
26
27    /// Decompression completed unsuccessfully with an implementation-specific message.
28    #[error("Decompression failed: {0}")]
29    DecompressionFailed(String),
30
31    /// Bytes did not match the expected machine format.
32    #[error("Invalid format: {0}")]
33    InvalidFormat(String),
34
35    /// Machine payload contained invalid data for the requested operation.
36    #[error("Invalid data: {0}")]
37    InvalidData(String),
38
39    /// Magic bytes did not match the expected machine header.
40    #[error("Invalid magic bytes")]
41    InvalidMagic,
42
43    /// Provided buffer was too small for the requested read or write.
44    #[error("Buffer too small: required {required}, got {actual}")]
45    BufferTooSmall {
46        /// Number of bytes required by the operation.
47        required: usize,
48        /// Number of bytes available in the provided buffer.
49        actual: usize,
50    },
51
52    /// Underlying I/O operation failed.
53    #[error("IO error: {0}")]
54    Io(#[from] std::io::Error),
55}