use thiserror::Error;
#[derive(Error, Debug)]
pub enum ComfyError {
#[error("ComfyUI returned HTTP {status}: {body}")]
Http { status: u16, body: String },
#[error("{0}")]
InvalidResponse(String),
#[error("Workflow node errors: {0}")]
NodeErrors(String),
#[error("Generation timed out")]
Timeout,
#[error("Generation failed: {0}")]
GenerationFailed(String),
#[error("Download for '{filename}' exceeded {limit_bytes} bytes (received {actual_bytes})")]
OutputTooLarge {
filename: String,
limit_bytes: usize,
actual_bytes: usize,
},
#[error("{context}: {source}")]
Network {
context: String,
source: reqwest::Error,
},
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
}
impl ComfyError {
pub fn kind(&self) -> &'static str {
match self {
Self::Http { .. } => "http",
Self::InvalidResponse(_) => "invalid_response",
Self::NodeErrors(_) => "node_errors",
Self::Timeout => "timeout",
Self::GenerationFailed(_) => "generation_failed",
Self::OutputTooLarge { .. } => "output_too_large",
Self::Network { .. } => "network",
Self::Json(_) => "json",
}
}
}
pub type Result<T> = std::result::Result<T, ComfyError>;