Skip to main content

shape_wire/
error.rs

1//! Error types for wire format operations
2
3use thiserror::Error;
4
5/// Wire format errors
6#[derive(Debug, Error)]
7pub enum WireError {
8    /// Serialization failed
9    #[error("Failed to serialize value: {0}")]
10    SerializationError(String),
11
12    /// Deserialization failed
13    #[error("Failed to deserialize value: {0}")]
14    DeserializationError(String),
15
16    /// Invalid value for conversion
17    #[error("Invalid value: {0}")]
18    InvalidValue(String),
19
20    /// Type mismatch
21    #[error("Type mismatch: expected {expected}, got {actual}")]
22    TypeMismatch { expected: String, actual: String },
23
24    /// Missing required field
25    #[error("Missing required field: {0}")]
26    MissingField(String),
27
28    /// Format not found
29    #[error("Format not found: {0}")]
30    FormatNotFound(String),
31
32    /// JSON error
33    #[error("JSON error: {0}")]
34    JsonError(#[from] serde_json::Error),
35}
36
37/// Result type for wire operations
38pub type Result<T> = std::result::Result<T, WireError>;
39
40impl From<rmp_serde::encode::Error> for WireError {
41    fn from(e: rmp_serde::encode::Error) -> Self {
42        WireError::SerializationError(e.to_string())
43    }
44}
45
46impl From<rmp_serde::decode::Error> for WireError {
47    fn from(e: rmp_serde::decode::Error) -> Self {
48        WireError::DeserializationError(e.to_string())
49    }
50}