Skip to main content

brainwires_training/
error.rs

1use thiserror::Error;
2
3/// Errors that can occur during training operations.
4#[derive(Error, Debug)]
5pub enum TrainingError {
6    /// Dataset-related error.
7    #[error("Dataset error: {0}")]
8    Dataset(#[from] brainwires_datasets::DatasetError),
9
10    /// API request error.
11    #[error("API error: {message} (status: {status_code})")]
12    Api {
13        /// Error message.
14        message: String,
15        /// HTTP status code.
16        status_code: u16,
17    },
18
19    /// Provider-specific error.
20    #[error("Provider error: {0}")]
21    Provider(String),
22
23    /// Configuration error.
24    #[error("Configuration error: {0}")]
25    Config(String),
26
27    /// Job not found.
28    #[error("Job not found: {0}")]
29    JobNotFound(String),
30
31    /// Job execution failed.
32    #[error("Job failed: {0}")]
33    JobFailed(String),
34
35    /// Dataset upload error.
36    #[error("Upload error: {0}")]
37    Upload(String),
38
39    /// Training backend error.
40    #[error("Training backend error: {0}")]
41    Backend(String),
42
43    /// I/O error.
44    #[error("I/O error: {0}")]
45    Io(#[from] std::io::Error),
46
47    /// JSON serialization error.
48    #[error("JSON error: {0}")]
49    Json(#[from] serde_json::Error),
50
51    /// HTTP request error.
52    #[error("HTTP error: {0}")]
53    #[cfg(feature = "cloud")]
54    Http(#[from] reqwest::Error),
55
56    /// Feature unsupported by a provider.
57    #[error("{provider}: {feature} is unsupported")]
58    NotImplemented {
59        /// Provider name.
60        provider: String,
61        /// Feature description.
62        feature: String,
63    },
64
65    /// Other unclassified error.
66    #[error("{0}")]
67    Other(String),
68}
69
70/// Result type alias for training operations.
71pub type TrainingResult<T> = Result<T, TrainingError>;