fix: 修复ComfyUI SDK的cargo check和clippy警告
- 修复ComfyUIError中WebSocket变体过大的问题,使用Box包装 - 添加自定义From实现处理Box包装的WebSocket错误 - 修复所有格式化字符串警告,使用内联格式化 - 移除无用的类型转换(reqwest::Error::from) - 修复代码质量问题: - 简化if语句嵌套 - 使用?操作符替代显式错误处理 - 优化map迭代方式 - 使用is_some_and替代map_or 修复内容: - 44个clippy警告全部解决 - 所有测试通过 - cargo check --lib 无错误无警告
This commit is contained in:
@@ -43,7 +43,7 @@ where
|
||||
last_error = Some(error);
|
||||
|
||||
if attempt < config.max_attempts {
|
||||
log::warn!("Attempt {} failed, retrying in {:?}", attempt, delay);
|
||||
log::warn!("Attempt {attempt} failed, retrying in {delay:?}");
|
||||
sleep(delay).await;
|
||||
|
||||
// Exponential backoff
|
||||
@@ -68,7 +68,7 @@ pub fn is_retryable_error(error: &ComfyUIError) -> bool {
|
||||
// Retry on network errors, timeouts, and 5xx status codes
|
||||
reqwest_error.is_timeout() ||
|
||||
reqwest_error.is_connect() ||
|
||||
reqwest_error.status().map_or(false, |status| status.is_server_error())
|
||||
reqwest_error.status().is_some_and(|status| status.is_server_error())
|
||||
}
|
||||
ComfyUIError::WebSocket(_) => true, // Most WebSocket errors are retryable
|
||||
ComfyUIError::Connection(_) => true,
|
||||
@@ -101,7 +101,7 @@ where
|
||||
last_error = Some(error);
|
||||
|
||||
if attempt < config.max_attempts {
|
||||
log::warn!("Attempt {} failed with retryable error, retrying in {:?}", attempt, delay);
|
||||
log::warn!("Attempt {attempt} failed with retryable error, retrying in {delay:?}");
|
||||
sleep(delay).await;
|
||||
|
||||
// Exponential backoff
|
||||
@@ -130,8 +130,7 @@ where
|
||||
match tokio::time::timeout(timeout, operation).await {
|
||||
Ok(result) => result,
|
||||
Err(_) => Err(ComfyUIError::timeout(format!(
|
||||
"Operation timed out after {:?}",
|
||||
timeout
|
||||
"Operation timed out after {timeout:?}"
|
||||
))),
|
||||
}
|
||||
}
|
||||
@@ -144,7 +143,7 @@ pub trait ErrorContext<T> {
|
||||
impl<T> ErrorContext<T> for Result<T> {
|
||||
fn with_context(self, context: &str) -> Result<T> {
|
||||
self.map_err(|error| {
|
||||
ComfyUIError::new(format!("{}: {}", context, error))
|
||||
ComfyUIError::new(format!("{context}: {error}"))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user