1use thiserror::Error;
2
3#[derive(Error, Debug)]
5pub enum ComfyError {
6 #[error("ComfyUI returned HTTP {status}: {body}")]
8 Http { status: u16, body: String },
9
10 #[error("{0}")]
12 InvalidResponse(String),
13
14 #[error("Workflow node errors: {0}")]
16 NodeErrors(String),
17
18 #[error("Generation timed out")]
20 Timeout,
21
22 #[error("Generation failed: {0}")]
24 GenerationFailed(String),
25
26 #[error("Download for '{filename}' exceeded {limit_bytes} bytes (received {actual_bytes})")]
28 OutputTooLarge {
29 filename: String,
30 limit_bytes: usize,
31 actual_bytes: usize,
32 },
33
34 #[error("{context}: {source}")]
36 Network {
37 context: String,
38 source: reqwest::Error,
39 },
40
41 #[error("JSON error: {0}")]
43 Json(#[from] serde_json::Error),
44}
45
46impl ComfyError {
47 pub fn kind(&self) -> &'static str {
49 match self {
50 Self::Http { .. } => "http",
51 Self::InvalidResponse(_) => "invalid_response",
52 Self::NodeErrors(_) => "node_errors",
53 Self::Timeout => "timeout",
54 Self::GenerationFailed(_) => "generation_failed",
55 Self::OutputTooLarge { .. } => "output_too_large",
56 Self::Network { .. } => "network",
57 Self::Json(_) => "json",
58 }
59 }
60}
61
62pub type Result<T> = std::result::Result<T, ComfyError>;