Skip to content
Snippets Groups Projects
Verified Commit 54dd3456 authored by Wiktor Kwapisiewicz's avatar Wiktor Kwapisiewicz
Browse files

fix: Print more details on errors

This PR changes two things:

1. It uses a newer version of `nethsm_sdk_rs` which fixes the "serde
error" issue reported upstream: [#30].

Previously the error message would indicate serde error:

```
Error: NetHsm(Api("Getting backup failed: error in serde: EOF while parsing a value at line 1 column 0"))
```

Now, they print the status code instead:

```
Error: NetHsm(Api("Getting backup failed: Status code: 401: "))
```

2. It explicitly handles the response error and prints the content
that the NetHSM API returns, in case it is available:

Instead of:

```
Error: NetHsm(Api("Getting key failed: in response: status code 412"))
```

it prints:

```
Error: NetHsm(Api("Getting key failed: Status code: 412: Service not
available"))
```

(`Service not available` is the error message returned by the NetHSM API)

[#30]: https://github.com/Nitrokey/nethsm-sdk-rs/issues/30

Fixes: #29


Signed-off-by: default avatarWiktor Kwapisiewicz <wiktor@metacode.biz>
parent 713b8598
No related branches found
No related tags found
No related merge requests found
......@@ -127,9 +127,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.87"
version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10f00e1f6e58a40e807377c75c6a7f97bf9044fab57816f2414e6f5f4499d7b8"
checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6"
[[package]]
name = "argon2"
......@@ -343,9 +343,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.1.18"
version = "1.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476"
checksum = "45bcde016d64c21da4be18b655631e5ab6d3107607e71a73a9f53eb48aae23fb"
dependencies = [
"shlex",
]
......@@ -1225,9 +1225,9 @@ dependencies = [
[[package]]
name = "iana-time-zone"
version = "0.1.60"
version = "0.1.61"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141"
checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220"
dependencies = [
"android_system_properties",
"core-foundation-sys",
......@@ -1563,8 +1563,7 @@ dependencies = [
[[package]]
name = "nethsm-sdk-rs"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ef50e7e369f89a28621b330b81e2eafb26823c9b2bd1ffda2356968567a0e23"
source = "git+https://github.com/Nitrokey/nethsm-sdk-rs?branch=errors#7a6732a351b843dcf59ef08b19d9287cdc7c9c4f"
dependencies = [
"base64 0.21.7",
"mime",
......@@ -2097,9 +2096,9 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.5.3"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4"
checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853"
dependencies = [
"bitflags",
]
......@@ -2349,9 +2348,9 @@ dependencies = [
[[package]]
name = "rustix"
version = "0.38.36"
version = "0.38.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f55e80d50763938498dd5ebb18647174e0c76dc38c5505294bb224624f30f36"
checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811"
dependencies = [
"bitflags",
"errno",
......@@ -2904,9 +2903,9 @@ dependencies = [
[[package]]
name = "toml_edit"
version = "0.22.20"
version = "0.22.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d"
checksum = "3b072cee73c449a636ffd6f32bd8de3a9f7119139aff882f44943ce2986dc5cf"
dependencies = [
"indexmap",
"serde",
......
......@@ -18,7 +18,7 @@ ed25519-dalek = { version = "2.1.1", features = ["pkcs8", "pem"] }
hex = { version = "0.4.3", features = ["serde"] }
log = "0.4.20"
md-5 = "0.10.6"
nethsm-sdk-rs = "1"
nethsm-sdk-rs = { version = "1", git = "https://github.com/Nitrokey/nethsm-sdk-rs", branch = "errors" }
p224 = { version = "0.13.2", features = ["pem", "pkcs8"] }
p256 = { version = "0.13.2", features = ["pem", "pkcs8"] }
p384 = { version = "0.13.0", features = ["pem", "pkcs8"] }
......
......@@ -77,6 +77,19 @@ impl<T> From<nethsm_sdk_rs::apis::Error<T>> for NetHsmApiError<T> {
message: Some(format!("{}", transport)),
},
},
nethsm_sdk_rs::apis::Error::ResponseError(resp) => Self {
error: None,
message: Some(format!(
"Status code: {}: {}",
resp.status,
// First, try to deserialize the response as a `Message` object,
// which is commonly returned by a majority of failures
serde_json::from_slice::<Message>(&resp.content)
.map(|m| m.message)
// if that fails, as a last resort, try to return the response verbatim.
.unwrap_or_else(|_| String::from_utf8_lossy(&resp.content).into())
)),
},
_ => Self {
error: Some(value),
message: None,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment