Files
imeepos e69ce2b817 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 无错误无警告
2025-08-08 16:12:25 +08:00

93 lines
2.4 KiB
Rust

//! Error types for the ComfyUI SDK
use thiserror::Error;
/// Result type alias for ComfyUI SDK operations
pub type Result<T> = std::result::Result<T, ComfyUIError>;
/// Main error type for ComfyUI SDK
#[derive(Error, Debug)]
pub enum ComfyUIError {
/// HTTP request errors
#[error("HTTP error: {0}")]
Http(#[from] reqwest::Error),
/// WebSocket errors
#[error("WebSocket error: {0}")]
WebSocket(#[from] Box<tokio_tungstenite::tungstenite::Error>),
/// JSON serialization/deserialization errors
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
/// URL parsing errors
#[error("URL error: {0}")]
Url(#[from] url::ParseError),
/// Template validation errors
#[error("Template validation error: {0}")]
TemplateValidation(String),
/// Parameter validation errors
#[error("Parameter validation error: {0}")]
ParameterValidation(String),
/// Connection errors
#[error("Connection error: {0}")]
Connection(String),
/// Execution errors
#[error("Execution error: {0}")]
Execution(String),
/// Timeout errors
#[error("Timeout error: {0}")]
Timeout(String),
/// Generic errors
#[error("Error: {0}")]
Generic(String),
/// IO errors
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
}
impl From<tokio_tungstenite::tungstenite::Error> for ComfyUIError {
fn from(error: tokio_tungstenite::tungstenite::Error) -> Self {
Self::WebSocket(Box::new(error))
}
}
impl ComfyUIError {
/// Create a new generic error
pub fn new(message: impl Into<String>) -> Self {
Self::Generic(message.into())
}
/// Create a new template validation error
pub fn template_validation(message: impl Into<String>) -> Self {
Self::TemplateValidation(message.into())
}
/// Create a new parameter validation error
pub fn parameter_validation(message: impl Into<String>) -> Self {
Self::ParameterValidation(message.into())
}
/// Create a new connection error
pub fn connection(message: impl Into<String>) -> Self {
Self::Connection(message.into())
}
/// Create a new execution error
pub fn execution(message: impl Into<String>) -> Self {
Self::Execution(message.into())
}
/// Create a new timeout error
pub fn timeout(message: impl Into<String>) -> Self {
Self::Timeout(message.into())
}
}