-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to
thiserror
for error handling
- Loading branch information
1 parent
0cb5e66
commit 1cec37a
Showing
5 changed files
with
50 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "ferium" | ||
version = "3.7.1" | ||
version = "3.7.2" | ||
edition = "2021" | ||
authors = ["theRookieCoder <[email protected]>"] | ||
description = "Ferium is an easy to use manager for Minecraft mods on Modrinth and Github Releases" | ||
|
@@ -12,15 +12,15 @@ publish = false | |
[dependencies] | ||
# Use `rustls` rather than OpenSSL | ||
reqwest = { version = "0", default-features = false, features = ["json", "rustls-tls"] } | ||
# Use bleeding edge version of `clap` | ||
clap = { git = "https://github.com/clap-rs/clap/", features = ["yaml"] } | ||
tokio = { version = "1", features = ["rt-multi-thread", "macros"] } | ||
clap = { version = "3.0.0-beta", features = ["yaml"] } | ||
serde = { version = "1", features = ["derive"] } | ||
fancy-regex = "0" | ||
shellexpand = "2" | ||
serde_json = "1" | ||
ansi_term = "0" | ||
dialoguer = "0" | ||
thiserror = "1" | ||
ferinth = "1" | ||
online = "3" | ||
bytes = "1" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,48 @@ | ||
use std::{ | ||
convert::From, | ||
fmt::{Debug, Formatter}, | ||
}; | ||
use std::fmt::Debug; | ||
use thiserror::Error; | ||
|
||
pub type FResult<T> = std::result::Result<T, FError>; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum FError { | ||
/// The config file does not contain mods or repos | ||
#[error("Your config file is empty! Run `ferium help` to see how to add mods or repositories")] | ||
EmptyConfigFile, | ||
/// An HTTP(S) request returned with an error | ||
ReqwestError { error: reqwest::Error }, | ||
#[error("Failed to send/process an HTTP(S) request due to {}", .0)] | ||
ReqwestError(#[from] reqwest::Error), | ||
/// Failure to unwrap an Option, akin to `NullPointerError`s | ||
#[error("Could not access an expected value")] | ||
OptionError, | ||
/// Failed to parse a regular expression | ||
RegexError, | ||
#[error("Failed to parse regular expression")] | ||
RegexError(#[from] fancy_regex::Error), | ||
/// A JSON error occured | ||
JsonError { | ||
category: serde_json::error::Category, | ||
}, | ||
#[error("{}", match .0.classify() { | ||
serde_json::error::Category::Syntax => { | ||
"Syntax error encountered in JSON file" | ||
}, | ||
serde_json::error::Category::Data => { | ||
"Non matching type while deserialising JSON" | ||
}, | ||
serde_json::error::Category::Eof => { | ||
"Unexpected end of file while reading JSON" | ||
}, | ||
serde_json::error::Category::Io => { | ||
"Encountered an Input/Output error while handling JSON" | ||
}, | ||
})] | ||
JsonError(#[from] serde_json::Error), | ||
/// An HTTP(S) request encountered an error | ||
#[error("An HTTP(S) request returned an error, {}", message)] | ||
HTTPError { message: String }, | ||
/// An I/O error occured | ||
IOError { description: String }, | ||
#[error("Encountered an input/output error, {}", .0.to_string())] | ||
IOError(#[from] std::io::Error), | ||
/// The program is running on an unsupported device | ||
#[error("The device you are currently running on is unsupported by Ferium")] | ||
InvalidDeviceError, | ||
/// The application should print `message` and quit (gracefully) | ||
#[error("{}", message)] | ||
Quit { message: String }, | ||
} | ||
|
||
impl Debug for FError { | ||
fn fmt(&self, fmt: &mut Formatter) -> Result<(), std::fmt::Error> { | ||
match self { | ||
FError::EmptyConfigFile => write!(fmt, "Your config file is empty! Run `ferium help` to see how to add mods or repositories"), | ||
FError::HTTPError { message } => write!(fmt, "An HTTP(S) request returned an error, {}", message), | ||
FError::InvalidDeviceError => write!(fmt, "The device you are currently running on is unsupported by Ferium"), | ||
FError::IOError {description} => write!(fmt, "Encountered an input/output error, {}", description), | ||
FError::JsonError { category } => match category { | ||
serde_json::error::Category::Syntax => { | ||
write!(fmt, "Syntax error encountered in JSON file") | ||
}, | ||
serde_json::error::Category::Data => { | ||
write!(fmt, "Non matching type while deserialising JSON") | ||
}, | ||
serde_json::error::Category::Eof => { | ||
write!(fmt, "Unexpected end of file while reading JSON") | ||
}, | ||
serde_json::error::Category::Io => { | ||
write!(fmt, "Encountered an Input/Output error while handling JSON") | ||
}, | ||
}, | ||
FError::OptionError => write!(fmt, "Could not access an expected value"), | ||
FError::Quit { message } => write!(fmt, "{}", message), | ||
FError::RegexError => write!(fmt, "Failed to parse regular expression"), | ||
FError::ReqwestError { error }=> write!(fmt, "Failed to send/process an HTTP(S) request due to {}", error), | ||
} | ||
} | ||
} | ||
|
||
impl From<reqwest::Error> for FError { | ||
fn from(err: reqwest::Error) -> Self { | ||
Self::ReqwestError { error: err } | ||
} | ||
} | ||
|
||
impl From<fancy_regex::Error> for FError { | ||
fn from(_: fancy_regex::Error) -> Self { | ||
Self::RegexError | ||
} | ||
} | ||
|
||
impl From<std::io::Error> for FError { | ||
fn from(err: std::io::Error) -> Self { | ||
Self::IOError { | ||
description: err.to_string(), | ||
} | ||
} | ||
} | ||
|
||
impl From<serde_json::Error> for FError { | ||
fn from(err: serde_json::Error) -> Self { | ||
Self::JsonError { | ||
category: err.classify(), | ||
} | ||
} | ||
} |