1
0
Fork 0
mirror of https://gitlab.com/news-flash/article_scraper.git synced 2025-07-08 00:19:59 +02:00
article_scraper/src/full_text_parser/config/error.rs
2022-10-08 23:09:00 +02:00

59 lines
1.3 KiB
Rust

use failure::{Backtrace, Context, Error, Fail};
use std::fmt;
#[derive(Debug)]
pub struct ConfigError {
inner: Context<ConfigErrorKind>,
}
#[derive(Copy, Clone, Eq, PartialEq, Debug, Fail)]
pub enum ConfigErrorKind {
#[fail(display = "IO Error")]
IO,
#[fail(display = "Unknown Error")]
Unknown,
}
impl Fail for ConfigError {
fn cause(&self) -> Option<&dyn Fail> {
self.inner.cause()
}
fn backtrace(&self) -> Option<&Backtrace> {
self.inner.backtrace()
}
}
impl fmt::Display for ConfigError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&self.inner, f)
}
}
// impl ConfigError {
// pub fn kind(&self) -> ConfigErrorKind {
// *self.inner.get_context()
// }
// }
impl From<ConfigErrorKind> for ConfigError {
fn from(kind: ConfigErrorKind) -> ConfigError {
ConfigError {
inner: Context::new(kind),
}
}
}
impl From<Context<ConfigErrorKind>> for ConfigError {
fn from(inner: Context<ConfigErrorKind>) -> ConfigError {
ConfigError { inner }
}
}
impl From<Error> for ConfigError {
fn from(_: Error) -> ConfigError {
ConfigError {
inner: Context::new(ConfigErrorKind::Unknown),
}
}
}