1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use thiserror::Error;
/// Primary error type for the mold crate ecosystem.
///
/// Provides structured error variants for the main failure modes so callers
/// can pattern-match on specific categories instead of string-matching.
/// The `Other` variant accepts any `anyhow::Error` as a catch-all.
#[derive(Debug, Error)]
pub enum MoldError {
/// Request validation failures (bad dimensions, empty prompt, etc.)
#[error("{0}")]
Validation(String),
/// Download/network issues
#[error("{0}")]
Download(String),
/// Config parsing/loading errors
#[error("{0}")]
Config(String),
/// HTTP client communication errors
#[error("{0}")]
Client(String),
/// Model doesn't exist or isn't downloaded
#[error("{0}")]
ModelNotFound(String),
/// Inference/generation errors
#[error("{0}")]
Inference(String),
/// Generic RunPod API error (non-auth, non-not-found)
#[error("{0}")]
RunPod(String),
/// RunPod authentication failure (401/403 or missing/invalid API key)
#[error("{0}")]
RunPodAuth(String),
/// RunPod resource not found (404)
#[error("{0}")]
RunPodNotFound(String),
/// RunPod could not schedule the pod (no machines available)
#[error("{0}")]
RunPodNoStock(String),
/// Catch-all for everything else
#[error(transparent)]
Other(#[from] anyhow::Error),
}
/// Convenience alias used across the crate.
pub type Result<T> = std::result::Result<T, MoldError>;
impl From<crate::download::DownloadError> for MoldError {
fn from(err: crate::download::DownloadError) -> Self {
MoldError::Download(err.to_string())
}
}