From 253437eb5198aa84989812fde7f9ea5983073974 Mon Sep 17 00:00:00 2001 From: Will Chandler Date: Tue, 11 Nov 2025 14:07:35 -0500 Subject: [PATCH 1/2] Don't panic on json-body failure Currently CLI clients will panic if the `json-body` file cannot be read or cannot be deserialized. Update these to return errors and add additional context. --- progenitor-impl/src/cli.rs | 5 +- .../tests/output/src/buildomat_cli.rs | 37 +- .../tests/output/src/cli_gen_cli.rs | 7 +- .../tests/output/src/keeper_cli.rs | 25 +- progenitor-impl/tests/output/src/nexus_cli.rs | 355 ++++++++++++------ .../tests/output/src/param_collision_cli.rs | 1 + .../tests/output/src/param_overrides_cli.rs | 1 + .../tests/output/src/propolis_server_cli.rs | 29 +- 8 files changed, 300 insertions(+), 160 deletions(-) diff --git a/progenitor-impl/src/cli.rs b/progenitor-impl/src/cli.rs index ed32ff95..27f4d840 100644 --- a/progenitor-impl/src/cli.rs +++ b/progenitor-impl/src/cli.rs @@ -88,6 +88,7 @@ impl Generator { let code = quote! { use #crate_path::*; + use anyhow::Context as _; pub struct Cli { client: Client, @@ -510,12 +511,12 @@ impl Generator { if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); + let body_txt = std::fs::read_to_string(value).with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::<#body_type_ident>( &body_txt, ) - .unwrap(); + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } } diff --git a/progenitor-impl/tests/output/src/buildomat_cli.rs b/progenitor-impl/tests/output/src/buildomat_cli.rs index 320e6bfe..8323f7e1 100644 --- a/progenitor-impl/tests/output/src/buildomat_cli.rs +++ b/progenitor-impl/tests/output/src/buildomat_cli.rs @@ -1,4 +1,5 @@ use crate::buildomat_builder::*; +use anyhow::Context as _; pub struct Cli { client: Client, config: T, @@ -465,8 +466,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -569,8 +572,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -637,8 +642,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -695,8 +702,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -753,8 +762,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -791,8 +802,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } diff --git a/progenitor-impl/tests/output/src/cli_gen_cli.rs b/progenitor-impl/tests/output/src/cli_gen_cli.rs index 00334461..0f5cdb38 100644 --- a/progenitor-impl/tests/output/src/cli_gen_cli.rs +++ b/progenitor-impl/tests/output/src/cli_gen_cli.rs @@ -1,4 +1,5 @@ use crate::cli_gen_builder::*; +use anyhow::Context as _; pub struct Cli { client: Client, config: T, @@ -56,8 +57,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } diff --git a/progenitor-impl/tests/output/src/keeper_cli.rs b/progenitor-impl/tests/output/src/keeper_cli.rs index ba309f20..b521d4a1 100644 --- a/progenitor-impl/tests/output/src/keeper_cli.rs +++ b/progenitor-impl/tests/output/src/keeper_cli.rs @@ -1,4 +1,5 @@ use crate::keeper_builder::*; +use anyhow::Context as _; pub struct Cli { client: Client, config: T, @@ -216,8 +217,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -296,8 +299,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -322,8 +327,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -358,8 +365,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } diff --git a/progenitor-impl/tests/output/src/nexus_cli.rs b/progenitor-impl/tests/output/src/nexus_cli.rs index 0e71b6a0..f6aef7a1 100644 --- a/progenitor-impl/tests/output/src/nexus_cli.rs +++ b/progenitor-impl/tests/output/src/nexus_cli.rs @@ -1,4 +1,5 @@ use crate::nexus_builder::*; +use anyhow::Context as _; pub struct Cli { client: Client, config: T, @@ -6149,8 +6150,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -6177,8 +6180,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -6215,9 +6220,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = - serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -6276,8 +6282,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -6310,9 +6318,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = - serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -6449,8 +6458,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -6511,8 +6522,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -6589,9 +6602,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = - serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -6664,8 +6678,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -6726,8 +6742,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -6835,8 +6853,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -7036,8 +7056,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -7196,8 +7218,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -7347,8 +7371,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -7389,8 +7415,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -7463,8 +7491,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -7574,9 +7604,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = - serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -7665,9 +7696,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = - serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -7925,8 +7957,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -8014,8 +8048,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -8162,8 +8198,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -8236,8 +8274,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -8333,9 +8373,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = - serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -8431,8 +8472,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -8516,8 +8559,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -8658,9 +8703,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = - serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -8753,9 +8799,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = - serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -8899,8 +8946,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -8984,8 +9033,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -9116,8 +9167,10 @@ impl Cli { pub async fn execute_policy_update(&self, matches: &::clap::ArgMatches) -> anyhow::Result<()> { let mut request = self.client.policy_update(); if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -9298,8 +9351,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -9495,8 +9550,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -9811,8 +9868,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -9925,8 +9984,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -9979,8 +10040,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -10068,8 +10131,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -10098,8 +10163,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -10180,8 +10247,10 @@ impl Cli { ) -> anyhow::Result<()> { let mut request = self.client.ip_pool_service_range_add(); if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -10206,8 +10275,10 @@ impl Cli { ) -> anyhow::Result<()> { let mut request = self.client.ip_pool_service_range_remove(); if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -10296,8 +10367,10 @@ impl Cli { ) -> anyhow::Result<()> { let mut request = self.client.system_policy_update(); if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -10429,8 +10502,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -10547,8 +10622,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -10609,8 +10686,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -10671,9 +10750,12 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = - serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| { + format!("failed to deserialize {} as JSON", value.display()) + })?; request = request.body(body_value); } @@ -10754,8 +10836,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -11042,8 +11126,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -11206,8 +11292,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -11363,8 +11451,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -11405,8 +11495,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -11447,8 +11539,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -11691,8 +11785,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -11753,8 +11849,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -11831,9 +11929,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = - serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -11912,8 +12011,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -11981,8 +12082,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -12071,8 +12174,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -12227,8 +12332,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } diff --git a/progenitor-impl/tests/output/src/param_collision_cli.rs b/progenitor-impl/tests/output/src/param_collision_cli.rs index 61a6e893..4a191033 100644 --- a/progenitor-impl/tests/output/src/param_collision_cli.rs +++ b/progenitor-impl/tests/output/src/param_collision_cli.rs @@ -1,4 +1,5 @@ use crate::param_collision_builder::*; +use anyhow::Context as _; pub struct Cli { client: Client, config: T, diff --git a/progenitor-impl/tests/output/src/param_overrides_cli.rs b/progenitor-impl/tests/output/src/param_overrides_cli.rs index 0f29a863..f7902296 100644 --- a/progenitor-impl/tests/output/src/param_overrides_cli.rs +++ b/progenitor-impl/tests/output/src/param_overrides_cli.rs @@ -1,4 +1,5 @@ use crate::param_overrides_builder::*; +use anyhow::Context as _; pub struct Cli { client: Client, config: T, diff --git a/progenitor-impl/tests/output/src/propolis_server_cli.rs b/progenitor-impl/tests/output/src/propolis_server_cli.rs index ed79ba2d..73ee7399 100644 --- a/progenitor-impl/tests/output/src/propolis_server_cli.rs +++ b/progenitor-impl/tests/output/src/propolis_server_cli.rs @@ -1,4 +1,5 @@ use crate::propolis_server_builder::*; +use anyhow::Context as _; pub struct Cli { client: Client, config: T, @@ -185,9 +186,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = - serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -243,9 +245,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = - serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -287,9 +290,10 @@ impl Cli { ) -> anyhow::Result<()> { let mut request = self.client.instance_state_put(); if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = - serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } @@ -318,9 +322,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = - serde_json::from_str::(&body_txt).unwrap(); + let body_txt = std::fs::read_to_string(value) + .with_context(|| format!("failed to read {}", value.display()))?; + let body_value = serde_json::from_str::(&body_txt) + .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; request = request.body(body_value); } From 4b9c12b0baef8b42d7da1dd1ff212a1b8a32cc0a Mon Sep 17 00:00:00 2001 From: Will Chandler Date: Thu, 13 Nov 2025 15:52:22 -0500 Subject: [PATCH 2/2] Simplify deserialization error --- progenitor-impl/src/cli.rs | 2 +- .../tests/output/src/buildomat_cli.rs | 12 +- .../tests/output/src/cli_gen_cli.rs | 2 +- .../tests/output/src/keeper_cli.rs | 8 +- progenitor-impl/tests/output/src/nexus_cli.rs | 116 +++++++++--------- .../tests/output/src/propolis_server_cli.rs | 8 +- 6 files changed, 73 insertions(+), 75 deletions(-) diff --git a/progenitor-impl/src/cli.rs b/progenitor-impl/src/cli.rs index 27f4d840..e1bdf30c 100644 --- a/progenitor-impl/src/cli.rs +++ b/progenitor-impl/src/cli.rs @@ -516,7 +516,7 @@ impl Generator { serde_json::from_str::<#body_type_ident>( &body_txt, ) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } } diff --git a/progenitor-impl/tests/output/src/buildomat_cli.rs b/progenitor-impl/tests/output/src/buildomat_cli.rs index 8323f7e1..78445f66 100644 --- a/progenitor-impl/tests/output/src/buildomat_cli.rs +++ b/progenitor-impl/tests/output/src/buildomat_cli.rs @@ -469,7 +469,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -575,7 +575,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -645,7 +645,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -705,7 +705,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -765,7 +765,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -805,7 +805,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } diff --git a/progenitor-impl/tests/output/src/cli_gen_cli.rs b/progenitor-impl/tests/output/src/cli_gen_cli.rs index 0f5cdb38..2b060a9d 100644 --- a/progenitor-impl/tests/output/src/cli_gen_cli.rs +++ b/progenitor-impl/tests/output/src/cli_gen_cli.rs @@ -60,7 +60,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } diff --git a/progenitor-impl/tests/output/src/keeper_cli.rs b/progenitor-impl/tests/output/src/keeper_cli.rs index b521d4a1..f1616003 100644 --- a/progenitor-impl/tests/output/src/keeper_cli.rs +++ b/progenitor-impl/tests/output/src/keeper_cli.rs @@ -220,7 +220,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -302,7 +302,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -330,7 +330,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -368,7 +368,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } diff --git a/progenitor-impl/tests/output/src/nexus_cli.rs b/progenitor-impl/tests/output/src/nexus_cli.rs index f6aef7a1..8359ddca 100644 --- a/progenitor-impl/tests/output/src/nexus_cli.rs +++ b/progenitor-impl/tests/output/src/nexus_cli.rs @@ -6153,7 +6153,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -6183,7 +6183,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -6223,7 +6223,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -6285,7 +6285,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -6321,7 +6321,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -6461,7 +6461,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -6525,7 +6525,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -6605,7 +6605,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -6681,7 +6681,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -6745,7 +6745,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -6856,7 +6856,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -7059,7 +7059,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -7221,7 +7221,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -7374,7 +7374,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -7418,7 +7418,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -7494,7 +7494,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -7607,7 +7607,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -7699,7 +7699,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -7960,7 +7960,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -8051,7 +8051,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -8201,7 +8201,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -8277,7 +8277,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -8376,7 +8376,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -8475,7 +8475,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -8562,7 +8562,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -8706,7 +8706,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -8802,7 +8802,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -8949,7 +8949,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -9036,7 +9036,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -9170,7 +9170,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -9354,7 +9354,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -9553,7 +9553,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -9871,7 +9871,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -9987,7 +9987,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -10043,7 +10043,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -10134,7 +10134,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -10166,7 +10166,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -10250,7 +10250,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -10278,7 +10278,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -10370,7 +10370,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -10505,7 +10505,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -10625,7 +10625,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -10689,7 +10689,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -10753,9 +10753,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| { - format!("failed to deserialize {} as JSON", value.display()) - })?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -10839,7 +10837,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -11129,7 +11127,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -11295,7 +11293,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -11454,7 +11452,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -11498,7 +11496,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -11542,7 +11540,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -11788,7 +11786,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -11852,7 +11850,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -11932,7 +11930,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -12014,7 +12012,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -12085,7 +12083,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -12177,7 +12175,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -12335,7 +12333,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } diff --git a/progenitor-impl/tests/output/src/propolis_server_cli.rs b/progenitor-impl/tests/output/src/propolis_server_cli.rs index 73ee7399..a644265b 100644 --- a/progenitor-impl/tests/output/src/propolis_server_cli.rs +++ b/progenitor-impl/tests/output/src/propolis_server_cli.rs @@ -189,7 +189,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -248,7 +248,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -293,7 +293,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); } @@ -325,7 +325,7 @@ impl Cli { let body_txt = std::fs::read_to_string(value) .with_context(|| format!("failed to read {}", value.display()))?; let body_value = serde_json::from_str::(&body_txt) - .with_context(|| format!("failed to deserialize {} as JSON", value.display()))?; + .with_context(|| format!("failed to parse {}", value.display()))?; request = request.body(body_value); }