99 lines
3.1 KiB
Rust
99 lines
3.1 KiB
Rust
//! Custom error type representing all possible error variants for peach-web.
|
|
|
|
use std::io::Error as IoError;
|
|
|
|
use golgi::GolgiError;
|
|
use peach_lib::error::PeachError;
|
|
use peach_lib::{serde_json, serde_yaml};
|
|
use serde_json::error::Error as JsonError;
|
|
use serde_yaml::Error as YamlError;
|
|
|
|
/// Custom error type encapsulating all possible errors for the web application.
|
|
#[derive(Debug)]
|
|
pub enum PeachWebError {
|
|
FailedToRegisterDynDomain(String),
|
|
Golgi(GolgiError),
|
|
HomeDir,
|
|
Io(IoError),
|
|
Json(JsonError),
|
|
OsString,
|
|
PeachLib { source: PeachError, msg: String },
|
|
System(String),
|
|
Yaml(YamlError),
|
|
}
|
|
|
|
impl std::error::Error for PeachWebError {
|
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
|
match *self {
|
|
PeachWebError::FailedToRegisterDynDomain(_) => None,
|
|
PeachWebError::Golgi(ref source) => Some(source),
|
|
PeachWebError::HomeDir => None,
|
|
PeachWebError::Io(ref source) => Some(source),
|
|
PeachWebError::Json(ref source) => Some(source),
|
|
PeachWebError::OsString => None,
|
|
PeachWebError::PeachLib { ref source, .. } => Some(source),
|
|
PeachWebError::System(_) => None,
|
|
PeachWebError::Yaml(ref source) => Some(source),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Display for PeachWebError {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
match *self {
|
|
PeachWebError::FailedToRegisterDynDomain(ref msg) => {
|
|
write!(f, "DYN DNS error: {}", msg)
|
|
}
|
|
PeachWebError::Golgi(ref source) => write!(f, "Golgi error: {}", source),
|
|
PeachWebError::HomeDir => write!(
|
|
f,
|
|
"Filesystem error: failed to determine home directory path"
|
|
),
|
|
PeachWebError::Io(ref source) => write!(f, "IO error: {}", source),
|
|
PeachWebError::Json(ref source) => write!(f, "Serde JSON error: {}", source),
|
|
PeachWebError::OsString => write!(
|
|
f,
|
|
"Filesystem error: failed to convert OsString to String for go-ssb directory path"
|
|
),
|
|
PeachWebError::PeachLib { ref source, .. } => write!(f, "{}", source),
|
|
PeachWebError::System(ref msg) => {
|
|
write!(f, "system error: {}", msg)
|
|
}
|
|
PeachWebError::Yaml(ref source) => write!(f, "Serde YAML error: {}", source),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<GolgiError> for PeachWebError {
|
|
fn from(err: GolgiError) -> PeachWebError {
|
|
PeachWebError::Golgi(err)
|
|
}
|
|
}
|
|
|
|
impl From<IoError> for PeachWebError {
|
|
fn from(err: IoError) -> PeachWebError {
|
|
PeachWebError::Io(err)
|
|
}
|
|
}
|
|
|
|
impl From<JsonError> for PeachWebError {
|
|
fn from(err: JsonError) -> PeachWebError {
|
|
PeachWebError::Json(err)
|
|
}
|
|
}
|
|
|
|
impl From<PeachError> for PeachWebError {
|
|
fn from(err: PeachError) -> PeachWebError {
|
|
PeachWebError::PeachLib {
|
|
source: err,
|
|
msg: "".to_string(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<YamlError> for PeachWebError {
|
|
fn from(err: YamlError) -> PeachWebError {
|
|
PeachWebError::Yaml(err)
|
|
}
|
|
}
|