use thiserror::Error;
pub type Result<T> = std::result::Result<T, GdownError>;
#[derive(Debug, Error)]
pub enum GdownError {
#[error("URL parsing failed: {0}")]
UrlError(#[from] url::ParseError),
#[error("File URL retrieval failed: {0}")]
FileUrlRetrieval(String),
#[error("Download failed: {0}")]
Download(String),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Hash mismatch: expected {expected}, got {actual}")]
HashMismatch { expected: String, actual: String },
#[error("File not found: {0}")]
FileNotFound(String),
#[error("Archive extraction failed: {0}")]
Extraction(String),
#[error("Invalid Google Drive URL: {0}")]
InvalidUrl(String),
#[error("Cache error: {0}")]
Cache(String),
}
impl GdownError {
pub fn exit_code(&self) -> i32 {
match self {
GdownError::UrlError(_) => 2,
GdownError::FileUrlRetrieval(_) => 3,
GdownError::Download(_) => 4,
GdownError::Io(_) => 5,
GdownError::HashMismatch { .. } => 7,
GdownError::FileNotFound(_) => 8,
GdownError::Extraction(_) => 9,
GdownError::InvalidUrl(_) => 10,
GdownError::Cache(_) => 11,
}
}
}