From 32ed0dd881abdd55af384bf80bbb8a644659ba38 Mon Sep 17 00:00:00 2001 From: Jason Travis Smith Date: Sat, 11 Mar 2017 13:08:02 -0500 Subject: [PATCH] Handling unhandled errors better. Now the Unhandled error contains the errno value for reference. --- src/c/errno.rs | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/c/errno.rs b/src/c/errno.rs index fe8d29c..925979c 100644 --- a/src/c/errno.rs +++ b/src/c/errno.rs @@ -43,6 +43,9 @@ pub enum CError /// There was a detected error, but it /// is not one handled by CError. Unhandled + { + errno: i32 + } } @@ -53,11 +56,18 @@ impl CError pub fn is_handled_error(errno: i32) -> bool { let error: CError; + let unhandled: CError; + + // Create an error that would be if this was unhandled. + unhandled = CError::Unhandled + { + errno: errno + }; // Turn the error value into a CError and // check if it is an Unhandled error. error = CError::from(errno); - if error != CError::Unhandled + if error != unhandled { true } @@ -76,7 +86,7 @@ impl CError /// Set the current Error for the system. pub fn set_current_error(error: CError) { - set_errno(error as i32); + set_errno(error.into()); } /// Clear the current Error. @@ -113,7 +123,22 @@ impl From for CError EDOM => { CError::Domain } ERANGE => { CError::Range } EILSEQ => { CError::IllegalSequence } - _ => { CError::Unhandled } + _ => { CError::Unhandled { errno: val } } + } + } +} + +impl Into for CError +{ + fn into(self) -> i32 + { + match self + { + CError::None => { NO_ERROR } + CError::Domain => { EDOM } + CError::Range => { ERANGE } + CError::IllegalSequence => { EILSEQ } + CError::Unhandled { errno: val } => { val } } } } @@ -128,7 +153,8 @@ impl Error for CError CError::Domain => { "Math argument out of domain of function" } CError::Range => { "Math result not representable" } CError::IllegalSequence => { "Illegal byte sequence" } - CError::Unhandled => { "Detected an Error not handled by CError" } + CError::Unhandled { errno: _val } => + { "Detected an Error not handled by CError" } } }