You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lolistealer/src/error.rs

112 lines
2.0 KiB

use std::{
error,
fmt,
io,
};
use super::{
tempfile,
loli,
tags,
};
#[derive(Debug)]
pub enum Error
{
Unknown,
IO(io::Error),
HTTP(reqwest::Error),
HTTPStatus(reqwest::StatusCode),
TempFile(tempfile::error::Error),
Tags(tags::OwnedError),
Loli(loli::error::Error),
ChildPanic
}
impl error::Error for Error
{
fn source(&self) -> Option<&(dyn error::Error + 'static)>
{
match &self {
Error::IO(io) => Some(io),
Error::Loli(lo) => Some(lo),
_ => None
}
}
}
impl fmt::Display for Error
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
match self {
Error::TempFile(tf) => write!(f, "tf recovered: {}", tf),
Error::IO(io) => write!(f, "io: {}", io),
Error::HTTP(http) => write!(f, "http internal error: {}", http),
Error::HTTPStatus(status) => write!(f, "response returned status code {}", status),
Error::Loli(loli) => write!(f, "loli interpretation: {}", loli),
Error::Tags(tags) => write!(f, "no match for tags: {}", tags),
Error::ChildPanic => write!(f, "child panic"),
_ => write!(f, "unknown error"),
}
}
}
impl From<io::Error> for Error
{
fn from(er: io::Error) -> Self
{
Self::IO(er)
}
}
impl From<reqwest::Error> for Error
{
fn from(er: reqwest::Error) -> Self
{
match er.status() {
Some(status) => Self::HTTPStatus(status),
None => Self::HTTP(er),
}
}
}
impl From<tempfile::error::Error> for Error
{
fn from(er: tempfile::error::Error) -> Self
{
Self::TempFile(er)
}
}
impl From<loli::error::Error> for Error
{
fn from(er: loli::error::Error) -> Self
{
Self::Loli(er)
}
}
impl From<loli::error::DecodeError> for Error
{
fn from(er: loli::error::DecodeError) -> Self
{
Self::Loli(er.into())
}
}
impl From<tags::Error<'_>> for Error
{
fn from(er: tags::Error<'_>) -> Self
{
Self::Tags(er.into())
}
}
impl From<tags::OwnedError> for Error
{
fn from(er: tags::OwnedError) -> Self
{
Self::Tags(er)
}
}