From b605614e5b3dab828e4f33c300836deab421be34 Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Fri, 28 Aug 2020 18:44:45 -0700 Subject: Use anyhow for error handling This patch changes our error handling approach from the ground up: instead of having a globally used Error enum that contains variants for all possible errors, we now use anyhow's Error type. This approach is more dynamic (and not statically typed), but it allows for more fine grained error messages and overall more user-friendly error reporting. Overall it also is a net simplification. While we have one dynamic cast now, in order to be able to handle erroneous password/PIN entries correctly, that is considered a reasonable compromise. --- src/tests/pws.rs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'src/tests/pws.rs') diff --git a/src/tests/pws.rs b/src/tests/pws.rs index 7f8107e..910ef92 100644 --- a/src/tests/pws.rs +++ b/src/tests/pws.rs @@ -25,12 +25,8 @@ fn set_invalid_slot(model: nitrokey::Model) { .handle(&["pws", "set", "100", "name", "login", "1234"]) .unwrap_err() .to_string(); - let expected = format!( - "Could not write PWS slot: {}", - nitrokey::Error::LibraryError(nitrokey::LibraryError::InvalidSlot) - ); - assert_eq!(err, expected); + assert_eq!(err, "Failed to write PWS slot"); } #[test_device] @@ -97,11 +93,7 @@ fn set_reset_get(model: nitrokey::Model) -> crate::Result<()> { let res = ncli.handle(&["pws", "get", "2"]); let err = res.unwrap_err().to_string(); - let expected = format!( - "Could not access PWS slot: {}", - nitrokey::Error::CommandError(nitrokey::CommandError::SlotNotProgrammed) - ); - assert_eq!(err, expected); + assert_eq!(err, "Failed to access PWS slot"); Ok(()) } @@ -113,10 +105,6 @@ fn clear(model: nitrokey::Model) -> crate::Result<()> { let res = ncli.handle(&["pws", "get", "10"]); let err = res.unwrap_err().to_string(); - let expected = format!( - "Could not access PWS slot: {}", - nitrokey::Error::CommandError(nitrokey::CommandError::SlotNotProgrammed) - ); - assert_eq!(err, expected); + assert_eq!(err, "Failed to access PWS slot"); Ok(()) } -- cgit v1.2.3