rocketmq_remoting/
error_helpers.rs1use rocketmq_error::RocketMQError;
24
25#[inline]
27pub fn io_error(err: std::io::Error) -> RocketMQError {
28 RocketMQError::IO(err)
29}
30
31#[inline]
33pub fn connection_invalid(msg: impl Into<String>) -> RocketMQError {
34 RocketMQError::network_connection_failed("unknown", msg)
35}
36
37#[inline]
39pub fn remote_error(msg: impl Into<String>) -> RocketMQError {
40 RocketMQError::network_connection_failed("remote", msg)
41}
42
43#[inline]
45pub fn decoder_error(ext_fields_len: usize, header_len: usize) -> RocketMQError {
46 RocketMQError::Protocol(rocketmq_error::unified::ProtocolError::DecodeError {
47 ext_fields_len,
48 header_len,
49 })
50}
51
52#[inline]
54pub fn deserialize_header_error(msg: impl Into<String>) -> RocketMQError {
55 RocketMQError::Serialization(rocketmq_error::unified::SerializationError::DecodeFailed {
56 format: "header",
57 message: msg.into(),
58 })
59}
60
61#[inline]
63pub fn decoding_error(required: usize, available: usize) -> RocketMQError {
64 RocketMQError::Serialization(rocketmq_error::unified::SerializationError::DecodeFailed {
65 format: "binary",
66 message: format!("required {} bytes, got {}", required, available),
67 })
68}
69
70#[inline]
72pub fn unsupported_serialize_type(serialize_type: u8) -> RocketMQError {
73 RocketMQError::Protocol(
74 rocketmq_error::unified::ProtocolError::UnsupportedSerializationType { serialize_type },
75 )
76}
77
78#[inline]
80pub fn illegal_argument(msg: impl Into<String>) -> RocketMQError {
81 RocketMQError::illegal_argument(msg)
82}
83
84#[inline]
86pub fn channel_send_failed(msg: impl Into<String>) -> RocketMQError {
87 RocketMQError::network_connection_failed("channel", format!("send failed: {}", msg.into()))
88}
89
90#[inline]
92pub fn channel_recv_failed(msg: impl Into<String>) -> RocketMQError {
93 RocketMQError::network_connection_failed("channel", format!("receive failed: {}", msg.into()))
94}
95
96#[inline]
98pub fn abort_process_error(code: i32, msg: impl Into<String>) -> RocketMQError {
99 RocketMQError::Internal(format!("Abort process error {}: {}", code, msg.into()))
100}
101
102#[inline]
104pub fn encoder_error(msg: impl Into<String>) -> RocketMQError {
105 RocketMQError::Serialization(rocketmq_error::unified::SerializationError::EncodeFailed {
106 format: "command",
107 message: msg.into(),
108 })
109}