2019-01-18 19:08:40 +01:00
|
|
|
// Copyright (c) 2019 Rodolphe Bréard
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2018-12-29 16:56:56 +01:00
|
|
|
use crate::entry::Entry;
|
2019-01-05 13:00:09 +01:00
|
|
|
use crate::event_handlers::EventHandler;
|
2018-12-29 21:03:33 +01:00
|
|
|
use std::fmt;
|
2018-12-29 16:56:56 +01:00
|
|
|
|
|
|
|
pub struct Error {
|
|
|
|
message: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Error {
|
|
|
|
pub fn new(msg: &str) -> Self {
|
|
|
|
Error {
|
|
|
|
message: msg.to_string(),
|
|
|
|
}
|
|
|
|
}
|
2018-12-29 21:03:33 +01:00
|
|
|
}
|
2018-12-29 16:56:56 +01:00
|
|
|
|
2018-12-29 21:03:33 +01:00
|
|
|
impl fmt::Display for Error {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "{}", self.message)
|
2018-12-29 16:56:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<std::io::Error> for Error {
|
|
|
|
fn from(error: std::io::Error) -> Self {
|
2018-12-29 20:26:23 +01:00
|
|
|
Error::new(&format!("IO error: {}", error))
|
2018-12-29 16:56:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-17 19:53:04 +01:00
|
|
|
impl From<log::SetLoggerError> for Error {
|
|
|
|
fn from(error: log::SetLoggerError) -> Self {
|
|
|
|
Error::new(&format!("Logger error: {}", error))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-29 16:56:56 +01:00
|
|
|
impl From<nom::Err<&str>> for Error {
|
|
|
|
fn from(error: nom::Err<&str>) -> Self {
|
|
|
|
let msg = match error {
|
|
|
|
nom::Err::Incomplete(_) => "not enough data".to_string(),
|
|
|
|
nom::Err::Error(c) => format!("{:?}", c),
|
|
|
|
nom::Err::Failure(c) => format!("{:?}", c),
|
|
|
|
};
|
2018-12-29 20:26:23 +01:00
|
|
|
Error::new(&format!("Parsing error: {}", msg))
|
2018-12-29 16:56:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<std::sync::mpsc::SendError<Entry>> for Error {
|
|
|
|
fn from(error: std::sync::mpsc::SendError<Entry>) -> Self {
|
2018-12-29 20:26:23 +01:00
|
|
|
Error::new(&format!("IO error: {}", error))
|
2018-12-29 16:56:56 +01:00
|
|
|
}
|
|
|
|
}
|
2019-01-05 13:00:09 +01:00
|
|
|
|
2019-01-12 00:17:59 +01:00
|
|
|
impl<T> From<std::sync::mpsc::SendError<EventHandler<T>>> for Error {
|
|
|
|
fn from(error: std::sync::mpsc::SendError<EventHandler<T>>) -> Self {
|
2019-01-05 13:00:09 +01:00
|
|
|
Error::new(&format!("IO error: {}", error))
|
|
|
|
}
|
|
|
|
}
|