1
0
Fork 0
mirror of https://gitlab.com/news-flash/article_scraper.git synced 2025-07-08 16:40:00 +02:00

port failure -> thiserror

This commit is contained in:
Jan Lukas Gernert 2022-12-01 09:22:08 +01:00
parent d906f6b7fe
commit 27be5a3204
11 changed files with 137 additions and 366 deletions

View file

@ -1,57 +1,15 @@
use failure::{Backtrace, Context, Error, Fail};
use std::fmt;
use crate::{
full_text_parser::{config::ConfigError, error::FullTextParserError},
images::ImageDownloadError,
};
use thiserror::Error;
#[derive(Debug)]
pub struct ScraperError {
inner: Context<ScraperErrorKind>,
}
#[derive(Copy, Clone, Eq, PartialEq, Debug, Fail)]
pub enum ScraperErrorKind {
#[fail(display = "Unknown Error")]
Unknown,
}
impl Fail for ScraperError {
fn cause(&self) -> Option<&dyn Fail> {
self.inner.cause()
}
fn backtrace(&self) -> Option<&Backtrace> {
self.inner.backtrace()
}
}
impl fmt::Display for ScraperError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&self.inner, f)
}
}
impl ScraperError {
pub fn kind(&self) -> ScraperErrorKind {
*self.inner.get_context()
}
}
impl From<ScraperErrorKind> for ScraperError {
fn from(kind: ScraperErrorKind) -> ScraperError {
ScraperError {
inner: Context::new(kind),
}
}
}
impl From<Context<ScraperErrorKind>> for ScraperError {
fn from(inner: Context<ScraperErrorKind>) -> ScraperError {
ScraperError { inner }
}
}
impl From<Error> for ScraperError {
fn from(_: Error) -> ScraperError {
ScraperError {
inner: Context::new(ScraperErrorKind::Unknown),
}
}
#[derive(Error, Debug)]
pub enum ScraperError {
#[error("")]
Config(#[from] ConfigError),
#[error("")]
Image(#[from] ImageDownloadError),
#[error("")]
Scrap(#[from] FullTextParserError),
}