1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
use crate::entry; use std::convert::From; use std::error::Error; use std::fmt::{Display, Formatter, Result as FmtResult}; use std::time::SystemTimeError; #[derive(Debug)] pub enum RMesgError { NotImplementedForThisPlatform, UnableToObtainSystemTime, UnableToAddDurationToSystemTime, KLogTimestampsDisabled, IntegerOutOfBound(String), Utf8StringConversionError(String), IOError(String), InternalError(String), EntryParsingError(String), UnableToObtainElapsedTime(SystemTimeError), DevKMsgFileOpenError(String), } impl Error for RMesgError {} impl Display for RMesgError { fn fmt(&self, f: &mut Formatter) -> FmtResult { write!( f, "RMesgError:: {}", match self { Self::NotImplementedForThisPlatform => "RMesg not implemented for this platform.".to_owned(), Self::IntegerOutOfBound(s) => format!("IntegerOutOfBound: {}", s), Self::Utf8StringConversionError(s) => format!("Utf8StringConversionError: {}", s), Self::IOError(s) => format!("std::io::Error: {}", s), Self::InternalError(s) => format!("InternalError: {}", s), Self::EntryParsingError(s) => format!("EntryParsingError: {}", s), Self::UnableToObtainElapsedTime(s) => format!("UnableToObtainElapsedTime: {}", s), Self::UnableToObtainSystemTime => "Failed to get SystemTime.".to_owned(), Self::UnableToAddDurationToSystemTime => "Failed to add a Duration to SystemTime".to_owned(), Self::KLogTimestampsDisabled => "Kernel Log timestamps are disabled".to_owned(), Self::DevKMsgFileOpenError(s) => s.to_owned(), } ) } } impl From<std::string::FromUtf8Error> for RMesgError { fn from(err: std::string::FromUtf8Error) -> RMesgError { RMesgError::Utf8StringConversionError(format!("{:?}", err)) } } impl From<std::io::Error> for RMesgError { fn from(err: std::io::Error) -> RMesgError { RMesgError::IOError(format!("{:?}", err)) } } impl From<entry::EntryParsingError> for RMesgError { fn from(err: entry::EntryParsingError) -> RMesgError { RMesgError::EntryParsingError(format!("{:?}", err)) } }