lighty_core/
errors.rs

1use thiserror::Error;
2
3/// Errors related to operating system and architecture detection
4#[derive(Debug, Error)]
5pub enum SystemError {
6    #[error("Unsupported operating system")]
7    UnsupportedOS,
8
9    #[error("Unsupported architecture")]
10    UnsupportedArchitecture,
11
12    #[error("IO error: {0}")]
13    Io(#[from] std::io::Error),
14}
15
16/// Errors related to file extraction (ZIP and tar.gz)
17#[derive(Debug, Error)]
18pub enum ExtractError {
19    #[error("Invalid ZIP entry at index {index}")]
20    ZipEntryNotFound { index: usize },
21
22    #[error("Path has no parent directory")]
23    InvalidPath,
24
25    #[error("Absolute paths not allowed: {path}")]
26    AbsolutePath { path: String },
27
28    #[error("Path traversal detected: {path} escapes base directory")]
29    PathTraversal { path: String },
30
31    #[error("File too large: {size} bytes (max: {max})")]
32    FileTooLarge { size: u64, max: u64 },
33
34    #[error("ZIP error: {0}")]
35    Zip(#[from] async_zip::error::ZipError),
36
37    #[error("TAR error: {0}")]
38    Tar(#[from] std::io::Error),
39}
40
41/// Errors related to HTTP downloads
42#[derive(Debug, Error)]
43pub enum DownloadError {
44    #[error("HTTP request failed: {0}")]
45    Http(#[from] reqwest::Error),
46
47    #[error("IO error: {0}")]
48    Io(#[from] std::io::Error),
49}
50
51/// Type alias for System operations results
52pub type SystemResult<T> = Result<T, SystemError>;
53
54/// Type alias for extraction operations results
55pub type ExtractResult<T> = Result<T, ExtractError>;
56
57/// Errors related to application state initialization
58#[derive(Debug, Error)]
59pub enum AppStateError {
60    #[error("Failed to create project directories")]
61    ProjectDirsCreation,
62
63    #[error("AppState not initialized")]
64    NotInitialized,
65}
66
67/// Type alias for download operations results
68pub type DownloadResult<T> = Result<T, DownloadError>;
69
70/// Type alias for app state operations results
71pub type AppStateResult<T> = Result<T, AppStateError>;