use thiserror::Error;
pub type ErpcResult<T> = Result<T, ErpcError>;
#[derive(Error, Debug)]
pub enum ErpcError {
#[error("Transport error: {0}")]
Transport(#[from] TransportError),
#[error("Codec error: {0}")]
Codec(#[from] CodecError),
#[error("Serialization error: {0}")]
Serialization(#[from] SerializationError),
#[error("Request error: {0}")]
Request(#[from] RequestError),
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("Invalid value: {0}")]
InvalidValue(String),
#[error("{0}")]
Other(String),
}
#[derive(Error, Debug)]
pub enum TransportError {
#[error("Connection failed: {0}")]
ConnectionFailed(String),
#[error("Send failed: {0}")]
SendFailed(String),
#[error("Receive failed: {0}")]
ReceiveFailed(String),
#[error("Transport is closed")]
Closed,
#[error("Timeout occurred")]
Timeout,
}
#[derive(Error, Debug)]
pub enum CodecError {
#[error("Unsupported codec version: {0}")]
UnsupportedVersion(u8),
#[error("Invalid message format: {0}")]
InvalidFormat(String),
#[error("Buffer overflow")]
BufferOverflow,
#[error("Buffer underflow")]
BufferUnderflow,
#[error("Invalid parameter: {0}")]
InvalidParameter(String),
#[error("Operation not supported: {0}")]
NotSupported(String),
}
#[derive(Error, Debug)]
pub enum SerializationError {
#[error("Serialization failed: {0}")]
SerializationFailed(String),
#[error("Deserialization failed: {0}")]
DeserializationFailed(String),
#[error("Invalid enum value: {value} for type {type_name}")]
InvalidEnumValue { value: i32, type_name: String },
#[error("Missing required field: {0}")]
MissingField(String),
#[error("Type mismatch: expected {expected}, found {found}")]
TypeMismatch { expected: String, found: String },
#[error("Invalid data format: {0}")]
InvalidDataFormat(String),
}
#[derive(Error, Debug)]
pub enum RequestError {
#[error("Invalid message type")]
InvalidMessageType,
#[error("Unexpected sequence number: expected {expected}, got {actual}")]
UnexpectedSequence { expected: u32, actual: u32 },
#[error("Invalid service ID: {0}")]
InvalidServiceId(u32),
#[error("Invalid method ID: {0}")]
InvalidMethodId(u32),
#[error("Method implementation error: {0}")]
MethodError(String),
}