Skip to main content

ros2_types/
error.rs

1//! Error types for type hash calculation
2
3use thiserror::Error;
4
5/// Result type for type hash operations
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Invalid RIHS format error details
9#[derive(Debug, Error)]
10pub enum InvalidRihsFormat {
11    /// String does not start with 'RIHS'
12    #[error("String does not start with 'RIHS'")]
13    MissingPrefix,
14
15    /// Invalid format structure
16    #[error("Expected format RIHS<version>_<hash>")]
17    InvalidStructure,
18
19    /// Could not extract version
20    #[error("Could not extract version from RIHS string")]
21    VersionExtractionFailed,
22
23    /// Invalid version number
24    #[error("Invalid version number: {version_str}")]
25    InvalidVersionNumber {
26        /// The invalid version string
27        version_str: String,
28    },
29}
30
31/// Type description error details
32#[derive(Debug, Error)]
33pub enum TypeDescriptionError {
34    /// Missing required field
35    #[error("Missing required field: {field_name}")]
36    MissingField {
37        /// Name of the missing field
38        field_name: String,
39    },
40
41    /// Invalid field value
42    #[error("Invalid value for field '{field_name}': {reason}")]
43    InvalidFieldValue {
44        /// Field name
45        field_name: String,
46        /// Reason for invalidity
47        reason: String,
48    },
49}
50
51/// Errors that can occur during type hash calculation
52#[derive(Debug, Error)]
53pub enum Error {
54    /// JSON serialization error
55    #[error(transparent)]
56    JsonError(#[from] serde_json::Error),
57
58    /// Invalid RIHS format
59    #[error(transparent)]
60    InvalidRihsFormat(#[from] InvalidRihsFormat),
61
62    /// Type description error
63    #[error(transparent)]
64    TypeDescriptionError(#[from] TypeDescriptionError),
65
66    /// CDR serialization error
67    #[error("CDR serialization error: {0}")]
68    CdrError(String),
69}