1extern crate alloc;
10
11use alloc::string::{String, ToString};
12use core::fmt;
13
14#[derive(Debug, Clone, PartialEq, Eq)]
16pub enum RpcError {
17 Codec(String),
19 PayloadTooLarge {
21 got: usize,
23 max: usize,
25 },
26 InvalidServiceName(String),
28 InvalidMethodName(String),
30 OnewayWithReturn(String),
32 OnewayWithOutParam {
34 method: String,
36 param: String,
38 },
39 DuplicateMethod(String),
41 DuplicateParam {
43 method: String,
45 param: String,
47 },
48 UnknownExceptionCode(u32),
50 EmptyService(String),
52 Timeout,
54 RemoteException(u32),
59 DuplicateInstanceName(String),
61 Dcps(String),
63 QosProfileNotFound(String),
65}
66
67impl fmt::Display for RpcError {
68 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
69 match self {
70 Self::Codec(s) => write!(f, "rpc codec error: {s}"),
71 Self::PayloadTooLarge { got, max } => {
72 write!(f, "rpc payload too large: {got} > {max}")
73 }
74 Self::InvalidServiceName(s) => write!(f, "invalid service name: {s:?}"),
75 Self::InvalidMethodName(s) => write!(f, "invalid method name: {s:?}"),
76 Self::OnewayWithReturn(m) => {
77 write!(f, "oneway method {m:?} must return void")
78 }
79 Self::OnewayWithOutParam { method, param } => write!(
80 f,
81 "oneway method {method:?} must not have out/inout param {param:?}"
82 ),
83 Self::DuplicateMethod(m) => write!(f, "duplicate method {m:?}"),
84 Self::DuplicateParam { method, param } => {
85 write!(f, "duplicate parameter {param:?} in method {method:?}")
86 }
87 Self::UnknownExceptionCode(v) => {
88 write!(f, "unknown RemoteExceptionCode_t discriminator {v}")
89 }
90 Self::EmptyService(n) => write!(f, "service {n:?} has no methods"),
91 Self::Timeout => write!(f, "rpc request timed out"),
92 Self::RemoteException(code) => {
93 write!(f, "remote exception code {code}")
94 }
95 Self::DuplicateInstanceName(n) => {
96 write!(f, "duplicate service instance name {n:?}")
97 }
98 Self::Dcps(s) => write!(f, "dcps error: {s}"),
99 Self::QosProfileNotFound(n) => {
100 write!(f, "qos profile {n:?} not found")
101 }
102 }
103 }
104}
105
106#[cfg(feature = "std")]
107impl std::error::Error for RpcError {}
108
109impl RpcError {
110 #[must_use]
112 pub fn codec(msg: &str) -> Self {
113 Self::Codec(msg.to_string())
114 }
115}
116
117pub type RpcResult<T> = core::result::Result<T, RpcError>;