Skip to main content

hdds_micro/
error.rs

1// SPDX-License-Identifier: Apache-2.0 OR MIT
2// Copyright (c) 2025-2026 naskel.com
3
4//! Error types for HDDS Micro
5
6use core::fmt;
7
8/// Result type for HDDS Micro operations
9pub type Result<T> = core::result::Result<T, Error>;
10
11/// Error type for HDDS Micro
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum Error {
14    /// Buffer too small for operation
15    BufferTooSmall,
16
17    /// Invalid RTPS header
18    InvalidHeader,
19
20    /// Invalid submessage
21    InvalidSubmessage,
22
23    /// CDR encoding error
24    EncodingError,
25
26    /// CDR decoding error
27    DecodingError,
28
29    /// Transport error
30    TransportError,
31
32    /// Participant not initialized
33    NotInitialized,
34
35    /// Entity not found
36    EntityNotFound,
37
38    /// Invalid parameter
39    InvalidParameter,
40
41    /// Resource exhausted (history full, etc.)
42    ResourceExhausted,
43
44    /// Operation timed out
45    Timeout,
46
47    /// Invalid or corrupted data
48    InvalidData,
49
50    /// Invalid encoding (e.g., unknown enum discriminator)
51    InvalidEncoding,
52}
53
54impl fmt::Display for Error {
55    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56        match self {
57            Error::BufferTooSmall => write!(f, "Buffer too small"),
58            Error::InvalidHeader => write!(f, "Invalid RTPS header"),
59            Error::InvalidSubmessage => write!(f, "Invalid submessage"),
60            Error::EncodingError => write!(f, "CDR encoding error"),
61            Error::DecodingError => write!(f, "CDR decoding error"),
62            Error::TransportError => write!(f, "Transport error"),
63            Error::NotInitialized => write!(f, "Participant not initialized"),
64            Error::EntityNotFound => write!(f, "Entity not found"),
65            Error::InvalidParameter => write!(f, "Invalid parameter"),
66            Error::ResourceExhausted => write!(f, "Resource exhausted"),
67            Error::Timeout => write!(f, "Operation timed out"),
68            Error::InvalidData => write!(f, "Invalid or corrupted data"),
69            Error::InvalidEncoding => write!(f, "Invalid encoding"),
70        }
71    }
72}
73
74#[cfg(feature = "std")]
75impl std::error::Error for Error {}