download_extract_progress/
error.rs

1use std::fmt::Display;
2
3use hex::FromHexError;
4
5/// Error type for download and extraction operations.
6#[derive(Debug)]
7pub enum DownloadError {
8    /// IO error occurred
9    IoError(std::io::Error),
10    /// HTTP request error
11    RequestError(reqwest::Error),
12    /// An invalid hash was provided, which could not be decoded
13    InvalidHash(FromHexError),
14    /// Hash mismatch error, containing the expected and actual hash.
15    HashMismatch(String, String)
16}
17
18impl Display for DownloadError {
19    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20        match self {
21            DownloadError::HashMismatch(expected, actual) => write!(f, "Hash mismatch: expected {}, got {}", expected, actual),
22            DownloadError::IoError(error) => write!(f, "IO error: {}", error),
23            DownloadError::RequestError(error) => write!(f, "Request error: {}", error),
24            DownloadError::InvalidHash(e) => write!(f, "Invalid hash: {}", e),
25        }
26    }
27}
28
29impl std::error::Error for DownloadError {}