aboutsummaryrefslogtreecommitdiff
path: root/nitrocli/src/tests/mod.rs
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2019-01-09 11:16:03 -0800
committerDaniel Mueller <deso@posteo.net>2019-01-09 11:16:03 -0800
commit3a99e7417e4c4eb30df9e711077c89b75764c029 (patch)
treebd56330e4809a9a1a7ed677c26a1b4805b31d30d /nitrocli/src/tests/mod.rs
parent6e0efd98e9ee07a01241e2187b4c820770c3c478 (diff)
downloadnitrocli-3a99e7417e4c4eb30df9e711077c89b75764c029.tar.gz
nitrocli-3a99e7417e4c4eb30df9e711077c89b75764c029.tar.bz2
Report command errors properly
So far we have taken all nitrokey::CommandError objects and put them in formatted form into the Error::Error variant. What we really should do, though, is to preserve the original error, with the additional context provided by the caller, and report that up the stack directly. Doing so has at least the benefit that we are able to check for expected errors without hard coding the textual representation as maintained by the nitrokey create. This change refactors the code accordingly and adds two tests for such expected error codes.
Diffstat (limited to 'nitrocli/src/tests/mod.rs')
-rw-r--r--nitrocli/src/tests/mod.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/nitrocli/src/tests/mod.rs b/nitrocli/src/tests/mod.rs
index ef8d2bd..4a4ab09 100644
--- a/nitrocli/src/tests/mod.rs
+++ b/nitrocli/src/tests/mod.rs
@@ -36,6 +36,7 @@ const NITROKEY_DEFAULT_USER_PIN: &str = "123456";
#[test_device]
fn dummy() {}
+mod otp;
mod pin;
mod run;
mod status;
@@ -44,6 +45,8 @@ mod status;
pub trait UnwrapError {
/// Unwrap an Error::Error variant.
fn unwrap_str_err(self) -> String;
+ /// Unwrap a Error::CommandError variant.
+ fn unwrap_cmd_err(self) -> (Option<&'static str>, nitrokey::CommandError);
}
impl<T> UnwrapError for crate::Result<T>
@@ -56,6 +59,13 @@ where
err => panic!("Unexpected error variant found: {:?}", err),
}
}
+
+ fn unwrap_cmd_err(self) -> (Option<&'static str>, nitrokey::CommandError) {
+ match self.unwrap_err() {
+ crate::Error::CommandError(ctx, err) => (ctx, err),
+ err => panic!("Unexpected error variant found: {:?}", err),
+ }
+ }
}
struct Nitrocli {