teascade-generator/src/error.rs

42 lines
947 B
Rust

use std::convert::From;
use std::io::Error as IOError;
use std::error::Error as STDError;
use logger::LogLevel;
#[derive(Debug)]
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 {
let mut os_error = String::new();
if let Some(error) = err.raw_os_error() {
os_error = format!("OS Error: {}", error);
}
Error {
description: format!("IOError: {} {}", err.description().to_owned(), os_error),
severity: LogLevel::SEVERE,
}
}
}