2018-04-16 15:58:16 +02:00
|
|
|
use std::convert::From;
|
|
|
|
use std::io::Error as IOError;
|
|
|
|
use std::error::Error as STDError;
|
|
|
|
|
|
|
|
use logger::LogLevel;
|
|
|
|
|
2018-04-20 01:52:48 +02:00
|
|
|
#[derive(Debug)]
|
2018-04-16 15:58:16 +02:00
|
|
|
pub struct Error {
|
|
|
|
description: String,
|
|
|
|
severity: LogLevel,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Error {
|
|
|
|
pub fn new<T: Into<String>>(severity: LogLevel, description: T) -> Error {
|
|
|
|
Error {
|
|
|
|
severity,
|
|
|
|
description: description.into(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn description(&self) -> String {
|
|
|
|
self.description.clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn severity(&self) -> LogLevel {
|
|
|
|
self.severity.clone()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<IOError> for Error {
|
|
|
|
fn from(err: IOError) -> Error {
|
2018-04-19 00:12:18 +02:00
|
|
|
let mut os_error = String::new();
|
|
|
|
if let Some(error) = err.raw_os_error() {
|
|
|
|
os_error = format!("OS Error: {}", error);
|
|
|
|
}
|
2018-04-16 15:58:16 +02:00
|
|
|
Error {
|
2018-04-19 00:12:18 +02:00
|
|
|
description: format!("IOError: {} {}", err.description().to_owned(), os_error),
|
2018-04-16 15:58:16 +02:00
|
|
|
severity: LogLevel::SEVERE,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|