1use crate::repository::ReleaseChannel;
2
3use std::path::PathBuf;
4
5#[derive(thiserror::Error, Debug)]
6pub enum FilesystemError {
7 #[error(transparent)]
8 Io(#[from] std::io::Error),
9 #[error(transparent)]
10 SerdeYaml(#[from] serde_yaml::Error),
11 #[error(transparent)]
12 Zip(#[from] zip::result::ZipError),
13 #[error(transparent)]
14 WalkDir(#[from] walkdir::Error),
15 #[error("File doesn't exist: {path:?}")]
16 FileDoesntExist { path: PathBuf },
17 #[cfg(target_os = "macos")]
18 #[error("Could not file bin name {bin_name} in archive")]
19 BinMissingFromTar { bin_name: String },
20 #[error("Failed to normalize path slashes for {path:?}")]
21 NormalizingPathSlash { path: PathBuf },
22 #[error("Could not strip prefix {prefix:?} from {from:?}")]
23 StripPrefix { prefix: String, from: String },
24}
25
26#[derive(thiserror::Error, Debug)]
27pub enum CacheError {
28 #[error("No repository information to create cache entry from addon {title}")]
29 AddonMissingRepo { title: String },
30 #[error(transparent)]
31 Filesystem(#[from] FilesystemError),
32}
33
34#[derive(thiserror::Error, Debug)]
35pub enum DownloadError {
36 #[error("Body len != content len: {body_length} != {content_length}")]
37 ContentLength {
38 content_length: u64,
39 body_length: u64,
40 },
41 #[error("Invalid status code {code} for url {url}")]
42 InvalidStatusCode {
43 code: isahc::http::StatusCode,
44 url: String,
45 },
46 #[error("No new release binary available for {bin_name}")]
47 MissingSelfUpdateRelease { bin_name: String },
48 #[error("Catalog failed to download")]
49 CatalogFailed,
50 #[error("Self update for linux only works from AppImage")]
51 SelfUpdateLinuxNonAppImage,
52 #[error(transparent)]
53 Isahc(#[from] isahc::Error),
54 #[error(transparent)]
55 Http(#[from] isahc::http::Error),
56 #[error(transparent)]
57 Var(#[from] std::env::VarError),
58 #[error(transparent)]
59 SerdeJson(#[from] serde_json::Error),
60 #[error(transparent)]
61 Filesystem(#[from] FilesystemError),
62}
63
64impl From<std::io::Error> for DownloadError {
65 fn from(e: std::io::Error) -> Self {
66 DownloadError::Filesystem(FilesystemError::Io(e))
67 }
68}
69
70#[derive(thiserror::Error, Debug)]
71pub enum RepositoryError {
72 #[error("No repository set for addon")]
73 AddonNoRepository,
74 #[error("Failed to parse curse id as u32: {id}")]
75 CurseIdConversion { id: String },
76 #[error("File id must be provided for curse changelog request")]
77 CurseChangelogFileId,
78 #[error("No package found for curse id {id}")]
79 CurseMissingPackage { id: String },
80 #[error("No package found for WowI id {id}")]
81 WowIMissingPackage { id: String },
82 #[error("No package found for Hub id {id}")]
83 HubMissingPackage { id: String },
84 #[error("No remote package found for channel {channel}")]
85 MissingPackageChannel { channel: ReleaseChannel },
86 #[error("Git repo must be created with `from_source_url`")]
87 GitWrongConstructor,
88 #[error("Invalid url {url}")]
89 GitInvalidUrl { url: String },
90 #[error("No valid host in {url}")]
91 GitMissingHost { url: String },
92 #[error("Invalid host {host}, only github.com and gitlab.com are supported")]
93 GitInvalidHost { host: String },
94 #[error("Author not present in {url}")]
95 GitMissingAuthor { url: String },
96 #[error("Repo not present in {url}")]
97 GitMissingRepo { url: String },
98 #[error("No release at {url}")]
99 GitMissingRelease { url: String },
100 #[error("{count} zip files on release, can't determine which to download for {url}")]
101 GitIndeterminableZip { count: usize, url: String },
102 #[error("{count} classic zip files on release, can't determine which to download for {url}")]
103 GitIndeterminableZipClassic { count: usize, url: String },
104 #[error("No zip available for {url}")]
105 GitNoZip { url: String },
106 #[error("Tag name must be specified for git changelog")]
107 GitChangelogTagName,
108 #[error(transparent)]
109 Download(#[from] DownloadError),
110 #[error(transparent)]
111 Filesystem(#[from] FilesystemError),
112 #[error(transparent)]
113 Uri(#[from] isahc::http::uri::InvalidUri),
114}
115
116impl From<std::io::Error> for RepositoryError {
117 fn from(e: std::io::Error) -> Self {
118 RepositoryError::Filesystem(FilesystemError::Io(e))
119 }
120}
121
122impl From<isahc::Error> for RepositoryError {
123 fn from(e: isahc::Error) -> Self {
124 RepositoryError::Download(DownloadError::Isahc(e))
125 }
126}
127
128#[derive(thiserror::Error, Debug)]
129pub enum ParseError {
130 #[error("Addon directory not found: {path:?}")]
131 MissingAddonDirectory { path: PathBuf },
132 #[error("No folders passed to addon")]
133 BuildAddonEmptyFolders,
134 #[error("No parent directory for {dir:?}")]
135 NoParentDirectory { dir: PathBuf },
136 #[error("Invalid UTF8 path: {path:?}")]
137 InvalidUtf8Path { path: PathBuf },
138 #[error("Path is not a file or doesn't exist: {path:?}")]
139 InvalidFile { path: PathBuf },
140 #[error("Invalid extension for path: {path:?}")]
141 InvalidExt { path: PathBuf },
142 #[error("Extension not in file parsing regex: {ext}")]
143 ParsingRegexMissingExt { ext: String },
144 #[error("Inclusion regex error for group {group} on pos {pos}, line: {line}")]
145 InclusionRegexError {
146 group: usize,
147 pos: usize,
148 line: String,
149 },
150 #[error(transparent)]
151 StripPrefix(#[from] std::path::StripPrefixError),
152 #[error(transparent)]
153 GlobPattern(#[from] glob::PatternError),
154 #[error(transparent)]
155 Glob(#[from] glob::GlobError),
156 #[error(transparent)]
157 FancyRegex(#[from] fancy_regex::Error),
158 #[error(transparent)]
159 Download(#[from] DownloadError),
160 #[error(transparent)]
161 Filesystem(#[from] FilesystemError),
162 #[error(transparent)]
163 Cache(#[from] CacheError),
164}
165
166impl From<std::io::Error> for ParseError {
167 fn from(e: std::io::Error) -> Self {
168 ParseError::Filesystem(FilesystemError::Io(e))
169 }
170}