hopr_chain_indexer/snapshot/
error.rs

1//! Error types for snapshot operations with user-friendly messages.
2//!
3//! This module defines comprehensive error types for all snapshot operations,
4//! providing clear error messages and actionable suggestions for users.
5
6use thiserror::Error;
7
8/// Comprehensive error type for snapshot operations with actionable guidance.
9///
10/// Each error variant includes:
11/// - A clear description of what went wrong
12/// - Suggestions for how users can resolve the issue
13/// - Relevant context information (e.g., required vs available space)
14///
15/// # Error Categories
16///
17/// - **Network errors**: Download failures, connectivity issues
18/// - **IO errors**: File system permissions, disk operations
19/// - **Validation errors**: Data integrity, format issues
20/// - **Resource errors**: Disk space, file size limits
21/// - **Configuration errors**: Invalid settings, missing parameters
22#[derive(Error, Debug)]
23pub enum SnapshotError {
24    /// Network-related errors during download operations.
25    /// Includes connection failures, DNS issues, and request timeouts.
26    #[error("Network error: {0}.")]
27    Network(#[from] reqwest::Error),
28
29    #[error("IO error: {0}.")]
30    Io(#[from] std::io::Error),
31
32    #[error("Archive extraction error: {0}.")]
33    Archive(String),
34
35    #[error("SQLite validation error: {0}.")]
36    Validation(String),
37
38    #[error("Invalid snapshot format: {0}.")]
39    InvalidFormat(String),
40
41    #[error("Insufficient disk space: required {required} MB, available {available} MB.")]
42    InsufficientSpace { required: u64, available: u64 },
43
44    #[error("Snapshot too large: {size} bytes exceeds maximum {max_size} bytes.")]
45    TooLarge { size: u64, max_size: u64 },
46
47    #[error("HTTP response error: status {status}.")]
48    HttpStatus { status: u16 },
49
50    #[error("Invalid data: {0}.")]
51    InvalidData(String),
52
53    #[error("Configuration error: {0}.")]
54    Configuration(String),
55
56    #[error("Timeout error: {0}.")]
57    Timeout(String),
58
59    #[error("Database installation error: {0}.")]
60    Installation(String),
61
62    #[error("The snapshot file is missing the required Content-Length header.")]
63    ContentLengthMissing(),
64}
65
66/// Specialized `Result` type for snapshot operations.
67///
68/// This type alias simplifies error handling throughout the snapshot module
69/// by providing a consistent return type for all operations.
70///
71/// # Example
72///
73/// ```no_run
74/// use hopr_chain_indexer::snapshot::error::SnapshotResult;
75///
76/// async fn download_file(url: &str) -> SnapshotResult<Vec<u8>> {
77///     // Implementation that may return various SnapshotError variants
78///     Ok(vec![])
79/// }
80/// ```
81pub type SnapshotResult<T> = Result<T, SnapshotError>;