use rocketmq_error::RocketMQError;
#[inline]
pub fn io_error(err: std::io::Error) -> RocketMQError {
RocketMQError::IO(err)
}
#[inline]
pub fn connection_invalid(msg: impl Into<String>) -> RocketMQError {
RocketMQError::network_connection_failed("unknown", msg)
}
#[inline]
pub fn remote_error(msg: impl Into<String>) -> RocketMQError {
RocketMQError::network_connection_failed("remote", msg)
}
#[inline]
pub fn decoder_error(ext_fields_len: usize, header_len: usize) -> RocketMQError {
RocketMQError::Protocol(rocketmq_error::unified::ProtocolError::DecodeError {
ext_fields_len,
header_len,
})
}
#[inline]
pub fn deserialize_header_error(msg: impl Into<String>) -> RocketMQError {
RocketMQError::Serialization(rocketmq_error::unified::SerializationError::DecodeFailed {
format: "header",
message: msg.into(),
})
}
#[inline]
pub fn decoding_error(required: usize, available: usize) -> RocketMQError {
RocketMQError::Serialization(rocketmq_error::unified::SerializationError::DecodeFailed {
format: "binary",
message: format!("required {} bytes, got {}", required, available),
})
}
#[inline]
pub fn unsupported_serialize_type(serialize_type: u8) -> RocketMQError {
RocketMQError::Protocol(rocketmq_error::unified::ProtocolError::UnsupportedSerializationType { serialize_type })
}
#[inline]
pub fn illegal_argument(msg: impl Into<String>) -> RocketMQError {
RocketMQError::illegal_argument(msg)
}
#[inline]
pub fn channel_send_failed(msg: impl Into<String>) -> RocketMQError {
RocketMQError::network_connection_failed("channel", format!("send failed: {}", msg.into()))
}
#[inline]
pub fn channel_recv_failed(msg: impl Into<String>) -> RocketMQError {
RocketMQError::network_connection_failed("channel", format!("receive failed: {}", msg.into()))
}
#[inline]
pub fn abort_process_error(code: i32, msg: impl Into<String>) -> RocketMQError {
RocketMQError::Internal(format!("Abort process error {}: {}", code, msg.into()))
}
#[inline]
pub fn encoder_error(msg: impl Into<String>) -> RocketMQError {
RocketMQError::Serialization(rocketmq_error::unified::SerializationError::EncodeFailed {
format: "command",
message: msg.into(),
})
}