diff options
author | ClementTsang <clementjhtsang@gmail.com> | 2019-09-14 21:48:29 -0400 |
---|---|---|
committer | ClementTsang <clementjhtsang@gmail.com> | 2019-09-14 21:48:29 -0400 |
commit | 48461756380e11533173eb1688e97203575687dd (patch) | |
tree | 0c7f6bdab94c29e43f553905416a2b657478896b /src/utils | |
parent | b75374be76047b60b2be49ed2789e633a7570a1c (diff) |
Added error util, finished network graph.
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/error.rs | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/src/utils/error.rs b/src/utils/error.rs index 411af11f..32df1fbf 100644 --- a/src/utils/error.rs +++ b/src/utils/error.rs @@ -1,2 +1,43 @@ -#[allow(dead_code)] -pub struct RustopError {} +use failure::Fail; +use std::result; + +/// A type alias for handling errors related to Rustop. +pub type Result<T> = result::Result<T, RustopError>; + +/// An error that can occur while Rustop runs. +#[derive(Debug, Fail)] +pub enum RustopError { + /// An error when there is an IO exception. + /// + /// The data provided is the error found. + #[fail(display = "ERROR: Encountered an IO exception: {}", message)] + InvalidIO { message : String }, + /// An error when there is an invalid argument passed in. + /// + /// The data provided is the error found. + #[fail(display = "ERROR: Invalid argument: {}", message)] + InvalidArg { message : String }, + /// An error when the heim library encounters a problem. + /// + /// The data provided is the error found. + #[fail(display = "ERROR: Invalid error during data collection due to Heim: {}", message)] + InvalidHeim { message : String }, +} + +impl From<std::io::Error> for RustopError { + fn from(err : std::io::Error) -> Self { + RustopError::InvalidIO { message : err.to_string() } + } +} + +impl From<heim::Error> for RustopError { + fn from(err : heim::Error) -> Self { + RustopError::InvalidHeim { message : err.to_string() } + } +} + +impl From<std::num::ParseIntError> for RustopError { + fn from(err : std::num::ParseIntError) -> Self { + RustopError::InvalidArg { message : err.to_string() } + } +} |