use crate::core::error::{ErrorCategory, ErrorCode, RetrySuggestion, XLinkError};
impl XLinkError {
#[inline]
pub fn channel_init_failed<S: Into<String>>(details: S, location: &'static str) -> Self {
Self::new_internal(
ErrorCode(201),
ErrorCategory::Channel,
"通道初始化失败".to_string(),
&format!("Failed to initialize channel: {}", details.into()),
location,
)
}
#[inline]
pub fn channel_disconnected<S: Into<String>>(reason: S, location: &'static str) -> Self {
let reason_str = reason.into();
Self::new_internal(
ErrorCode(202),
ErrorCategory::Channel,
"通道连接断开".to_string(),
&format!("Channel disconnected: {}", reason_str),
location,
)
.with_retry_suggestion(RetrySuggestion::Retryable {
max_attempts: 3,
base_delay_ms: 1000,
})
}
#[inline]
pub fn channel_send_failed<S: Into<String>>(
target: S,
error: S,
location: &'static str,
) -> Self {
Self::new_internal(
ErrorCode(203),
ErrorCategory::Channel,
"消息发送失败".to_string(),
&format!(
"Failed to send message to {}: {}",
target.into(),
error.into()
),
location,
)
.with_retry_suggestion(RetrySuggestion::Retryable {
max_attempts: 3,
base_delay_ms: 1000,
})
}
#[inline]
pub fn channel_receive_timeout<S: Into<String>>(channel: S, location: &'static str) -> Self {
Self::new_internal(
ErrorCode(204),
ErrorCategory::Channel,
"消息接收超时".to_string(),
&format!("Timeout waiting for message on channel: {}", channel.into()),
location,
)
.with_retry_suggestion(RetrySuggestion::Retryable {
max_attempts: 2,
base_delay_ms: 2000,
})
}
}