Skip to main content

loadsmith_thunderstore/
error.rs

1use std::path::PathBuf;
2
3/// Errors that can occur during thunderstore operations.
4///
5/// Covers I/O, serialization, SQLite, zip archive, glob, and API errors,
6/// as well as domain-specific errors such as missing manifests or
7/// unsupported loaders and platforms.
8///
9/// # Examples
10///
11/// ```
12/// use loadsmith_thunderstore::Error;
13///
14/// let err = Error::IndexNotComplete;
15/// assert_eq!(err.to_string(), "index is not built");
16/// ```
17#[derive(Debug, thiserror::Error)]
18pub enum Error {
19    #[error("I/O error")]
20    Io(#[from] std::io::Error),
21
22    #[error("zip error")]
23    Zip(#[from] zip::result::ZipError),
24
25    #[error("YAML error")]
26    Yaml(#[from] serde_yaml_ng::Error),
27
28    #[error("JSON error")]
29    Json(#[from] serde_json::Error),
30
31    #[error("SQLite error")]
32    Sqlite(#[from] rusqlite::Error),
33
34    #[error("glob error")]
35    Glob(#[from] globset::Error),
36
37    #[error("thunderstore client error")]
38    Thunderstore(#[from] thunderstore::Error),
39
40    #[error("non UTF-8 path: {0}")]
41    NonUtf8Path(PathBuf),
42
43    #[error("profile manifest not found in zip archive")]
44    ProfileManifestNotFound,
45
46    #[error("invalid zip file path: {0}")]
47    InvalidZipFilePath(PathBuf),
48
49    #[error("invalid thunderstore identifier: {0}")]
50    InvalidIdent(thunderstore::Error),
51
52    #[error("index is not built")]
53    IndexNotComplete,
54
55    #[error("distribution is missing identifier")]
56    DistributionIsMissingIdentifier,
57
58    #[error("invalid steam id")]
59    InvalidSteamId(#[source] std::num::ParseIntError),
60
61    #[error("unsupported tracking method: {0:?}")]
62    UnsupportedTrackingMethod(thunderstore::models::schema::TrackingMethod),
63
64    #[error("unsupported loader: {0:?}")]
65    UnsupportedLoader(thunderstore::models::schema::Loader),
66
67    #[error("unsupported platform: {0:?}")]
68    UnsupportedPlatform(thunderstore::models::schema::Platform),
69}
70
71/// A specialized [`Result`] type for thunderstore operations.
72///
73/// This type alias uses [`Error`] as the error variant.
74///
75/// # Examples
76///
77/// ```
78/// use loadsmith_thunderstore::Result;
79///
80/// fn example() -> Result<()> {
81///     Ok(())
82/// }
83/// ```
84pub type Result<T> = std::result::Result<T, Error>;