use thiserror::Error as ThisError;
use crate::event::Event;
#[derive(Debug, ThisError)]
pub enum Error {
#[error("IO error: `{0}`")]
IoError(#[from] std::io::Error),
#[error("channel receive error: `{0}`")]
ChannelReceiveError(#[from] std::sync::mpsc::RecvError),
#[error("channel send error: `{0}`")]
ChannelSendError(#[from] std::sync::mpsc::SendError<Event>),
#[error("CVE cache error: `{0:?}`")]
CacheError(nvd_cve::cache::CacheError),
#[error("Failed to parse color")]
ParseColorError,
#[error("Invalid range given. Please use the format <start:end>")]
RangeArgsError,
}
#[cfg(test)]
mod tests {
use super::*;
use std::io::{Error as IoError, ErrorKind};
#[test]
fn test_error() {
let message = "your computer is on fire!";
let error = Error::from(IoError::new(ErrorKind::Other, message));
assert_eq!(format!("IO error: `{message}`"), error.to_string());
assert_eq!(
format!("\"IO error: `{message}`\""),
format!("{:?}", error.to_string())
);
}
}