Add source to Error

This commit is contained in:
Paul Campbell 2023-08-05 18:06:29 +01:00
parent 6e2c3f8507
commit 536534bb04

View file

@ -3,11 +3,13 @@ use std::{str::Utf8Error, string::FromUtf8Error};
#[derive(Debug)]
pub struct Error {
pub details: String,
pub source: String,
}
impl Error {
pub fn message(details: &str) -> Self {
Self {
details: details.to_string(),
source: "(not provided)".to_string(),
}
}
}
@ -15,6 +17,7 @@ impl From<Utf8Error> for Error {
fn from(value: Utf8Error) -> Self {
Self {
details: value.to_string(),
source: "Utf8Error".to_string(),
}
}
}
@ -22,18 +25,23 @@ impl From<FromUtf8Error> for Error {
fn from(value: FromUtf8Error) -> Self {
Self {
details: value.to_string(),
source: "FromUtf8Error".to_string(),
}
}
}
impl From<String> for Error {
fn from(details: String) -> Self {
Self { details }
Self {
details,
source: "String".to_string(),
}
}
}
impl From<std::io::Error> for Error {
fn from(value: std::io::Error) -> Self {
Self {
details: value.to_string(),
source: "std::io::Error".to_string(),
}
}
}
@ -41,6 +49,7 @@ impl From<std::sync::mpsc::SendError<String>> for Error {
fn from(value: std::sync::mpsc::SendError<String>) -> Self {
Self {
details: value.to_string(),
source: "std::sync::mpsc::SendError".to_string(),
}
}
}
@ -48,6 +57,7 @@ impl From<atom_syndication::Error> for Error {
fn from(value: atom_syndication::Error) -> Self {
Self {
details: value.to_string(),
source: "atom_syndication::Error".to_string(),
}
}
}
@ -55,6 +65,7 @@ impl From<reqwest::Error> for Error {
fn from(value: reqwest::Error) -> Self {
Self {
details: value.to_string(),
source: "reqwest::Error".to_string(),
}
}
}