velesdb_migrate/
error.rs

1//! Error types for velesdb-migrate.
2
3use thiserror::Error;
4
5/// Migration error types.
6#[derive(Error, Debug)]
7pub enum Error {
8    /// Configuration error.
9    #[error("Configuration error: {0}")]
10    Config(String),
11
12    /// Connection error to source database.
13    #[error("Source connection error: {0}")]
14    SourceConnection(String),
15
16    /// Connection error to destination (`VelesDB`).
17    #[error("Destination connection error: {0}")]
18    DestinationConnection(String),
19
20    /// Data extraction error.
21    #[error("Extraction error: {0}")]
22    Extraction(String),
23
24    /// Data transformation error.
25    #[error("Transformation error: {0}")]
26    Transformation(String),
27
28    /// Data loading error.
29    #[error("Loading error: {0}")]
30    Loading(String),
31
32    /// Schema mismatch between source and destination.
33    #[error("Schema mismatch: {0}")]
34    SchemaMismatch(String),
35
36    /// Checkpoint/resume error.
37    #[error("Checkpoint error: {0}")]
38    Checkpoint(String),
39
40    /// HTTP request error.
41    #[error("HTTP error: {0}")]
42    Http(#[from] reqwest::Error),
43
44    /// JSON serialization/deserialization error.
45    #[error("JSON error: {0}")]
46    Json(#[from] serde_json::Error),
47
48    /// YAML parsing error.
49    #[error("YAML error: {0}")]
50    Yaml(#[from] serde_yaml::Error),
51
52    /// IO error.
53    #[error("IO error: {0}")]
54    Io(#[from] std::io::Error),
55
56    /// `VelesDB` core error.
57    #[error("VelesDB error: {0}")]
58    VelesDb(String),
59
60    /// Unsupported source type.
61    #[error("Unsupported source: {0}")]
62    UnsupportedSource(String),
63
64    /// Rate limit exceeded.
65    #[error("Rate limit exceeded, retry after {0} seconds")]
66    RateLimit(u64),
67
68    /// Authentication error.
69    #[error("Authentication failed: {0}")]
70    Authentication(String),
71}
72
73/// Result type alias for migration operations.
74pub type Result<T> = std::result::Result<T, Error>;
75
76#[cfg(test)]
77mod tests {
78    use super::*;
79
80    #[test]
81    fn test_error_display() {
82        let err = Error::Config("missing API key".to_string());
83        assert_eq!(err.to_string(), "Configuration error: missing API key");
84    }
85
86    #[test]
87    fn test_error_from_io() {
88        let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "file not found");
89        let err: Error = io_err.into();
90        assert!(matches!(err, Error::Io(_)));
91    }
92}