prometheus_wireguard_exporter/src/exporter_error.rs

102 lines
2.5 KiB
Rust
Raw Normal View History

use thiserror::Error;
#[derive(Error, Debug)]
pub enum FriendlyDescritionParseError {
#[error("unsupported header")]
UnsupportedHeader(String),
#[error("json parse error")]
SerdeJsonError(#[from] serde_json::Error),
}
#[derive(Debug, Error)]
2019-06-09 20:09:06 +02:00
pub enum PeerEntryParseError {
#[error("PublicKey entry not found in lines: {:?}", lines)]
2019-05-17 10:17:06 +02:00
PublicKeyNotFound { lines: Vec<String> },
#[error("AllowedIPs entry not found in lines: {:?}", lines)]
2019-05-17 10:17:06 +02:00
AllowedIPsEntryNotFound { lines: Vec<String> },
#[error("Friendly description parse error")]
FriendlyDescritionParseError(#[from] FriendlyDescritionParseError),
2019-05-17 10:17:06 +02:00
}
#[derive(Debug, Error)]
2019-06-09 20:09:06 +02:00
pub enum ExporterError {
2019-04-23 23:06:35 +02:00
#[allow(dead_code)]
#[error("Generic error")]
2019-04-23 23:06:35 +02:00
Generic {},
#[error("Hyper error: {}", e)]
Hyper { e: hyper::Error },
2019-04-23 23:06:35 +02:00
#[error("http error: {}", e)]
2019-04-23 23:06:35 +02:00
Http { e: http::Error },
#[error("UTF-8 error: {}", e)]
2019-04-23 23:06:35 +02:00
UTF8 { e: std::string::FromUtf8Error },
#[error("JSON format error: {}", e)]
Json { e: serde_json::error::Error },
2019-04-23 23:06:35 +02:00
#[error("IO Error: {}", e)]
2019-04-23 23:06:35 +02:00
IO { e: std::io::Error },
#[error("UTF8 conversion error: {}", e)]
2019-04-23 23:06:35 +02:00
Utf8 { e: std::str::Utf8Error },
#[error("int conversion error: {}", e)]
2019-04-23 23:06:35 +02:00
ParseInt { e: std::num::ParseIntError },
2019-05-17 10:17:06 +02:00
#[error("PeerEntry parse error: {}", e)]
2019-05-17 10:17:06 +02:00
PeerEntryParseError { e: PeerEntryParseError },
}
impl From<PeerEntryParseError> for ExporterError {
fn from(e: PeerEntryParseError) -> Self {
ExporterError::PeerEntryParseError { e }
}
2019-04-23 23:06:35 +02:00
}
impl From<std::io::Error> for ExporterError {
fn from(e: std::io::Error) -> Self {
ExporterError::IO { e }
}
}
impl From<hyper::Error> for ExporterError {
fn from(e: hyper::Error) -> Self {
2019-04-23 23:06:35 +02:00
ExporterError::Hyper { e }
}
}
impl From<http::Error> for ExporterError {
fn from(e: http::Error) -> Self {
ExporterError::Http { e }
}
}
impl From<std::string::FromUtf8Error> for ExporterError {
fn from(e: std::string::FromUtf8Error) -> Self {
ExporterError::UTF8 { e }
}
}
impl From<serde_json::error::Error> for ExporterError {
fn from(e: serde_json::error::Error) -> Self {
ExporterError::Json { e }
2019-04-23 23:06:35 +02:00
}
}
impl From<std::str::Utf8Error> for ExporterError {
fn from(e: std::str::Utf8Error) -> Self {
ExporterError::Utf8 { e }
}
}
impl From<std::num::ParseIntError> for ExporterError {
fn from(e: std::num::ParseIntError) -> Self {
ExporterError::ParseInt { e }
}
}