From ecc4743fdec43eb578e9c35bb008c68909f1517e Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Wed, 4 Sep 2024 17:32:19 +0200 Subject: better error handling --- src/errors.rs | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 src/errors.rs (limited to 'src/errors.rs') diff --git a/src/errors.rs b/src/errors.rs new file mode 100644 index 0000000..be2ca3c --- /dev/null +++ b/src/errors.rs @@ -0,0 +1,132 @@ +use std::{io, num::TryFromIntError, time::SystemTimeError}; + +use chrono::ParseError; +use indicatif::style::TemplateError; +use reqwest::StatusCode; + +use crate::db::DBError; + +pub type MLE = Result; + +#[derive(Debug, thiserror::Error)] +pub enum Error { + #[error("io: {source}")] + Io { + #[from] + source: io::Error, + }, + + #[error("tryfromint: {source}")] + TryFromInt { + #[from] + source: TryFromIntError, + }, + + #[error("serde_json: {source}")] + Json { + #[from] + source: serde_json::Error, + }, + + #[error("reqwest: {source}")] + Reqwest { + #[from] + source: reqwest::Error, + }, + + #[error("chrono parse error: {source}")] + ChronoParse { + #[from] + source: ParseError, + }, + + #[error("config: {source}")] + Config { + #[from] + source: config::ConfigError, + }, + + #[error("indicatif template: {source}")] + IndicatifTemplate { + #[from] + source: TemplateError, + }, + + #[error("toml: {source}")] + TomlSer { + #[from] + source: toml::ser::Error, + }, + + #[error("toml: {source}")] + TomlDeser { + #[from] + source: toml::de::Error, + }, + + #[error("systemtime: {source}")] + Systemtime { + #[from] + source: SystemTimeError, + }, + + #[error("conversion: {source}")] + Conversion { + #[from] + source: ConversionError, + }, + + #[error("Request didn't return 200 OK ({0})")] + RequestNotOK(StatusCode), + + #[error("ModError ({0})")] + ModError(String), + + #[error("No file extension where one should be")] + NoFileExtension, + + #[error("Desired path not found")] + PathNotFound, + + #[error("Desired system directory {0} not found")] + SysDirNotFound(String), + + #[error("No requested Minecraft version found")] + MinecraftVersionNotFound, + + #[error("Mod already added")] + ModAlreadyOnList, + + #[error("No versions are applicable for the current scope")] + NoCurrentVersion, + + #[error("The version does not know if it's locked or not")] + VersionSetNotSet, + + #[error("No download for the current id found")] + NoDownload, + + #[error("No ProjectInfo found / no id given")] + NoProjectInfo, + + #[error("The requested List was not found")] + ListNotFound, + + #[error("No download folder given")] + NoDownloadFolder, + + #[error("db: {source}")] + DB { + #[from] + source: DBError, + }, +} + +#[derive(Debug, thiserror::Error)] +pub enum ConversionError { + #[error("couldn't convert to Modloader from: {0}")] + Modloader(String), + + #[error("Path couldn't be converted to string")] + InvalidPath, +} -- cgit v1.2.3