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:
parent
d906f6b7fe
commit
27be5a3204
11 changed files with 137 additions and 366 deletions
68
src/error.rs
68
src/error.rs
|
@ -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),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue