gglib_core/ports/huggingface/
error.rs1use thiserror::Error;
4
5#[derive(Debug, Error)]
10pub enum HfPortError {
11 #[error("Model not found: {model_id}")]
13 ModelNotFound {
14 model_id: String,
16 },
17
18 #[error("Quantization '{quantization}' not found for model '{model_id}'")]
20 QuantizationNotFound {
21 model_id: String,
23 quantization: String,
25 },
26
27 #[error("Rate limit exceeded, try again later")]
29 RateLimited,
30
31 #[error("Authentication required for private model: {model_id}")]
33 AuthRequired {
34 model_id: String,
36 },
37
38 #[error("Network error: {message}")]
40 Network {
41 message: String,
43 },
44
45 #[error("Invalid API response: {message}")]
47 InvalidResponse {
48 message: String,
50 },
51
52 #[error("Configuration error: {message}")]
54 Configuration {
55 message: String,
57 },
58}
59
60pub type HfPortResult<T> = Result<T, HfPortError>;
62
63#[cfg(test)]
64mod tests {
65 use super::*;
66
67 #[test]
68 fn test_error_display() {
69 let err = HfPortError::ModelNotFound {
70 model_id: "TheBloke/Test-GGUF".to_string(),
71 };
72 assert!(err.to_string().contains("TheBloke/Test-GGUF"));
73
74 let err = HfPortError::QuantizationNotFound {
75 model_id: "Org/Model".to_string(),
76 quantization: "Q4_K_M".to_string(),
77 };
78 assert!(err.to_string().contains("Q4_K_M"));
79 assert!(err.to_string().contains("Org/Model"));
80 }
81}