diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2020-01-28 10:07:23 +0100 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2020-01-28 11:54:20 +0100 |
commit | da8727996efacec4280696caefee3feecea4eae7 (patch) | |
tree | 82f410d4009b698b630a90bcfa6255c07d743a33 /src/device | |
parent | 47795368c32c0c47a9c3da761c3adf0a36ca419f (diff) | |
download | nitrokey-rs-da8727996efacec4280696caefee3feecea4eae7.tar.gz nitrokey-rs-da8727996efacec4280696caefee3feecea4eae7.tar.bz2 |
Add String value to the Error::UnexpectedError variant
To make debugging of unexpected errors easier, this patch adds an
associated String value with a description of the unexpected behavior to
the UnexpectedError variant of the Error enum.
Diffstat (limited to 'src/device')
-rw-r--r-- | src/device/storage.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/device/storage.rs b/src/device/storage.rs index deb2844..1e2c46d 100644 --- a/src/device/storage.rs +++ b/src/device/storage.rs @@ -678,7 +678,7 @@ impl<'a> Storage<'a> { if usage_data.write_level_min > usage_data.write_level_max || usage_data.write_level_max > 100 { - Err(Error::UnexpectedError) + Err(Error::UnexpectedError("Invalid write levels".to_owned())) } else { Ok(ops::Range { start: usage_data.write_level_min, @@ -708,10 +708,14 @@ impl<'a> Storage<'a> { match status { 0..=100 => u8::try_from(status) .map(OperationStatus::Ongoing) - .map_err(|_| Error::UnexpectedError), + .map_err(|_| { + Error::UnexpectedError("Cannot create u8 from operation status".to_owned()) + }), -1 => Ok(OperationStatus::Idle), -2 => Err(get_last_error()), - _ => Err(Error::UnexpectedError), + _ => Err(Error::UnexpectedError( + "Invalid operation status".to_owned(), + )), } } |