diff options
| author | Jokler <jokler.contact@gmail.com> | 2018-02-28 01:21:25 +0100 |
|---|---|---|
| committer | Jokler <jokler.contact@gmail.com> | 2018-02-28 01:21:25 +0100 |
| commit | b40a984ed9b6a948265e1287ecc08f4e16c64ecd (patch) | |
| tree | 6b94762899961de9da57e426785c29d401b48442 /src/error.rs | |
| parent | 8ea98aab1ea34e0213380082577e2a3ff2d3aa2e (diff) | |
| download | frippy-b40a984ed9b6a948265e1287ecc08f4e16c64ecd.tar.gz frippy-b40a984ed9b6a948265e1287ecc08f4e16c64ecd.zip | |
Create errors with failure
The plugins are mostly not using the new errors yet and
the error handling in the Factoids plugin is just temporary.
Diffstat (limited to 'src/error.rs')
| -rw-r--r-- | src/error.rs | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..9ada5b6 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,98 @@ +//! Errors for `frippy` crate using `failure`. + +use std::io::Error as IoError; +use std::str::Utf8Error; +use irc::error::IrcError; +use reqwest::Error as ReqwestError; + +/// The main crate-wide error type. +#[derive(Debug, Fail)] +pub enum FrippyError { + /// A plugin error + #[fail(display = "A plugin error occured")] + Plugin(#[cause] PluginError), + + /// An IRC error + #[fail(display = "An IRC error occured")] + Irc(#[cause] IrcError), + + /// Missing config error + #[fail(display = "No config file was found")] + MissingConfig, + + /// A reqwest error + #[fail(display = "A reqwest error occured")] + Reqwest(#[cause] ReqwestError), + + /// An I/O error + #[fail(display = "An I/O error occured")] + Io(#[cause] IoError), + + /// A UTF8 error + #[fail(display = "A UTF8 error occured")] + Utf8(#[cause] Utf8Error), + + /// Reached download limit error + #[fail(display = "Reached download limit of {} KiB", limit)] + DownloadLimit { limit: usize }, +} + +/// Errors related to plugins +#[derive(Debug, Fail)] +pub enum PluginError { + /// A Url error + #[fail(display = "A Url error occured")] + Url(#[cause] UrlError), + + /// A Factoids error + #[fail(display = "{}", error)] + Factoids { error: String }, +} + +/// A URL plugin error +#[derive(Debug, Fail)] +pub enum UrlError { + /// Missing URL error + #[fail(display = "No URL was found")] + MissingUrl, + + /// Missing title error + #[fail(display = "No title was found")] + MissingTitle, +} + +impl From<UrlError> for FrippyError { + fn from(e: UrlError) -> FrippyError { + FrippyError::Plugin(PluginError::Url(e)) + } +} + +impl From<PluginError> for FrippyError { + fn from(e: PluginError) -> FrippyError { + FrippyError::Plugin(e) + } +} + +impl From<IrcError> for FrippyError { + fn from(e: IrcError) -> FrippyError { + FrippyError::Irc(e) + } +} + +impl From<ReqwestError> for FrippyError { + fn from(e: ReqwestError) -> FrippyError { + FrippyError::Reqwest(e) + } +} + +impl From<IoError> for FrippyError { + fn from(e: IoError) -> FrippyError { + FrippyError::Io(e) + } +} + +impl From<Utf8Error> for FrippyError { + fn from(e: Utf8Error) -> FrippyError { + FrippyError::Utf8(e) + } +} |
