ge_man_lib/
error.rs

1//! Possible errors that can be thrown by this crate.
2use std::io;
3
4use reqwest::blocking::Response;
5use thiserror::Error;
6
7use crate::tag::TagKind;
8
9/// Error for Steam config related problems.
10#[derive(Error, Debug)]
11pub enum SteamConfigError {
12    /// The Steam config contains no `CompatToolMapping` group/array.
13    #[error("Config to copy has no CompatToolMapping group")]
14    NoDefaultCompatToolAttribute,
15    /// An IO error occurred while working with the Steam config.
16    #[error("IO error occurred - Inspect the source for more information")]
17    IoError {
18        #[from]
19        source: io::Error,
20    },
21}
22
23/// Error for Lutris config related errors.
24#[derive(Error, Debug)]
25pub enum LutrisConfigError {
26    /// `$XDG_CONFIG_HOME/lutris/runners/wine.yml` contains no `version` attribute.
27    #[error("Config to copy has no version attribute")]
28    NoVersionAttribute,
29    /// An IO error occurred while working with the Lutris config.
30    #[error("IO error occurred - Inspect the source for more information")]
31    IoError {
32        #[from]
33        source: io::Error,
34    },
35}
36
37/// Errors for `serde` related issues.
38#[derive(Error, Debug)]
39pub enum DeserializeError {
40    /// Could not convert the JSON response of the GitHub API to a struct.
41    #[error("Could not convert Github JSON response into a struct")]
42    FailedToConvertToStruct {
43        #[from]
44        source: Box<dyn std::error::Error>,
45    },
46}
47
48/// Errors for GitHub API or `reqwest` related errors.
49#[derive(Debug, Error)]
50pub enum GithubError {
51    /// GitHub API response could not be converted with the `serde` crate.
52    #[error("Failed to convert GitHub resource with serde")]
53    SerdeDeserializeError {
54        #[from]
55        source: serde_json::Error,
56    },
57    /// Reqwest could not fetch a resource from the GitHub API.
58    #[error("Failed to fetch resource from GitHub API")]
59    ReqwestError {
60        #[from]
61        source: reqwest::Error,
62    },
63    /// The GitHub API returned no release tags.
64    #[error("No tags could be found")]
65    NoTags,
66    /// The GitHub API returned no assets for the fetched release.
67    #[error("For {tag} {kind} the release has no assets")]
68    ReleaseHasNoAssets { tag: String, kind: TagKind },
69    /// The response of the GitHub API is not HTTP code 200 (OK).
70    #[error("HTTP response status was not OK (200)")]
71    StatusNotOk(Response),
72}
73
74/// Error for when a `TagKind` can not be created.
75#[derive(Debug, Error)]
76pub enum TagKindError {
77    /// A `TagKind` could not be created from the provide string.
78    #[error("Could not create TagKind from provided string.")]
79    UnknownString,
80}