diff --git a/Cargo.lock b/Cargo.lock index d96490772..805331322 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -39,6 +39,7 @@ dependencies = [ "serde", "serde_bytes", "serde_json", + "serde_path_to_error", "serde_repr", "serde_with", "snafu", @@ -63,6 +64,7 @@ dependencies = [ "rstest", "serde", "serde_json", + "serde_path_to_error", "sha2", "snafu", ] @@ -100,6 +102,7 @@ dependencies = [ "serde", "serde_bytes", "serde_json", + "serde_path_to_error", "serde_repr", "serde_with", "sha2", @@ -1702,6 +1705,7 @@ dependencies = [ "serde", "serde_bytes", "serde_json", + "serde_path_to_error", "serde_repr", "serde_with", "snafu", @@ -1825,6 +1829,7 @@ dependencies = [ "serde", "serde_bytes", "serde_json", + "serde_path_to_error", "serde_repr", "serde_with", "snafu", @@ -2933,6 +2938,16 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_path_to_error" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59fab13f937fa393d08645bf3a84bdfe86e296747b506ada67bb15f10f218b2a" +dependencies = [ + "itoa", + "serde", +] + [[package]] name = "serde_repr" version = "0.1.20" diff --git a/api/oas_generator/rust_oas_generator/templates/apis/api.rs.j2 b/api/oas_generator/rust_oas_generator/templates/apis/api.rs.j2 index 22f14385b..d9744b5c9 100644 --- a/api/oas_generator/rust_oas_generator/templates/apis/api.rs.j2 +++ b/api/oas_generator/rust_oas_generator/templates/apis/api.rs.j2 @@ -100,7 +100,7 @@ pub async fn {{ operation.rust_function_name }}( match content_type { ContentType::Json => { let content = resp.text().await?; - serde_json::from_str(&content).map_err(Error::from) + serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_str(&content)).map_err(Error::from) }, ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `{{ get_success_response_type(operation) }}`"))), ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `{{ get_success_response_type(operation) }}`")))), diff --git a/api/oas_generator/rust_oas_generator/templates/apis/endpoint.rs.j2 b/api/oas_generator/rust_oas_generator/templates/apis/endpoint.rs.j2 index 7869180b5..574488876 100644 --- a/api/oas_generator/rust_oas_generator/templates/apis/endpoint.rs.j2 +++ b/api/oas_generator/rust_oas_generator/templates/apis/endpoint.rs.j2 @@ -208,9 +208,9 @@ pub async fn {{ operation.rust_function_name }}( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { message: e.to_string() }), + ContentType::Json => serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_slice(&response.body)).map_err(|e| Error::Serde { message: e.to_string() }), {% if operation.supports_msgpack %} - ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde { message: e.to_string() }), + ContentType::MsgPack => serde_path_to_error::deserialize(&mut rmp_serde::Deserializer::new(std::io::Cursor::new(&response.body))).map_err(|e| Error::Serde { message: e.to_string() }), {% else %} ContentType::MsgPack => Err(Error::Serde { message: "MsgPack not supported".to_string() }), {% endif %} diff --git a/api/oas_generator/rust_oas_generator/templates/base/Cargo.toml.j2 b/api/oas_generator/rust_oas_generator/templates/base/Cargo.toml.j2 index 6c56dbf5d..e122d5c00 100644 --- a/api/oas_generator/rust_oas_generator/templates/base/Cargo.toml.j2 +++ b/api/oas_generator/rust_oas_generator/templates/base/Cargo.toml.j2 @@ -20,6 +20,7 @@ serde_with = { version = "^3.8", default-features = false, features = [ "macros", ] } serde_json = "^1.0" +serde_path_to_error = "^0.1" serde_repr = "^0.1" serde_bytes = "^0.11" diff --git a/crates/algod_client/Cargo.toml b/crates/algod_client/Cargo.toml index 7e95b2b31..2f2513478 100644 --- a/crates/algod_client/Cargo.toml +++ b/crates/algod_client/Cargo.toml @@ -20,6 +20,7 @@ serde_with = { version = "^3.8", default-features = false, features = [ "macros", ] } serde_json = "^1.0" +serde_path_to_error = "^0.1" serde_repr = "^0.1" serde_bytes = "^0.11" diff --git a/crates/algod_client/src/apis/abort_catchup.rs b/crates/algod_client/src/apis/abort_catchup.rs index a1933b235..cec0ac017 100644 --- a/crates/algod_client/src/apis/abort_catchup.rs +++ b/crates/algod_client/src/apis/abort_catchup.rs @@ -69,7 +69,10 @@ pub async fn abort_catchup( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/account_application_information.rs b/crates/algod_client/src/apis/account_application_information.rs index b0ddea68a..bb8ae4966 100644 --- a/crates/algod_client/src/apis/account_application_information.rs +++ b/crates/algod_client/src/apis/account_application_information.rs @@ -85,10 +85,16 @@ pub async fn account_application_information( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), - ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::MsgPack => serde_path_to_error::deserialize( + &mut rmp_serde::Deserializer::new(std::io::Cursor::new(&response.body)), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::Text => { diff --git a/crates/algod_client/src/apis/account_asset_information.rs b/crates/algod_client/src/apis/account_asset_information.rs index 9f39a14d5..3bc576b97 100644 --- a/crates/algod_client/src/apis/account_asset_information.rs +++ b/crates/algod_client/src/apis/account_asset_information.rs @@ -72,7 +72,10 @@ pub async fn account_asset_information( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/account_assets_information.rs b/crates/algod_client/src/apis/account_assets_information.rs index 3b8544cbc..77a740596 100644 --- a/crates/algod_client/src/apis/account_assets_information.rs +++ b/crates/algod_client/src/apis/account_assets_information.rs @@ -79,7 +79,10 @@ pub async fn account_assets_information( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/account_information.rs b/crates/algod_client/src/apis/account_information.rs index f20280252..e14f5c292 100644 --- a/crates/algod_client/src/apis/account_information.rs +++ b/crates/algod_client/src/apis/account_information.rs @@ -75,7 +75,10 @@ pub async fn account_information( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/add_participation_key.rs b/crates/algod_client/src/apis/add_participation_key.rs index 945bf0a4a..3fdf1e703 100644 --- a/crates/algod_client/src/apis/add_participation_key.rs +++ b/crates/algod_client/src/apis/add_participation_key.rs @@ -73,10 +73,16 @@ pub async fn add_participation_key( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), - ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::MsgPack => serde_path_to_error::deserialize( + &mut rmp_serde::Deserializer::new(std::io::Cursor::new(&response.body)), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::Text => { diff --git a/crates/algod_client/src/apis/append_keys.rs b/crates/algod_client/src/apis/append_keys.rs index 599b1b99a..02cb668d0 100644 --- a/crates/algod_client/src/apis/append_keys.rs +++ b/crates/algod_client/src/apis/append_keys.rs @@ -77,10 +77,16 @@ pub async fn append_keys( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), - ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::MsgPack => serde_path_to_error::deserialize( + &mut rmp_serde::Deserializer::new(std::io::Cursor::new(&response.body)), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::Text => { diff --git a/crates/algod_client/src/apis/generate_participation_keys.rs b/crates/algod_client/src/apis/generate_participation_keys.rs index 315b23579..fde8f4f6a 100644 --- a/crates/algod_client/src/apis/generate_participation_keys.rs +++ b/crates/algod_client/src/apis/generate_participation_keys.rs @@ -81,7 +81,10 @@ pub async fn generate_participation_keys( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/get_application_box_by_name.rs b/crates/algod_client/src/apis/get_application_box_by_name.rs index b33772550..50e523a92 100644 --- a/crates/algod_client/src/apis/get_application_box_by_name.rs +++ b/crates/algod_client/src/apis/get_application_box_by_name.rs @@ -73,7 +73,10 @@ pub async fn get_application_box_by_name( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/get_application_boxes.rs b/crates/algod_client/src/apis/get_application_boxes.rs index 3360a499b..2fdff60cf 100644 --- a/crates/algod_client/src/apis/get_application_boxes.rs +++ b/crates/algod_client/src/apis/get_application_boxes.rs @@ -74,7 +74,10 @@ pub async fn get_application_boxes( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/get_application_by_id.rs b/crates/algod_client/src/apis/get_application_by_id.rs index 887ce7862..f67a37355 100644 --- a/crates/algod_client/src/apis/get_application_by_id.rs +++ b/crates/algod_client/src/apis/get_application_by_id.rs @@ -70,7 +70,10 @@ pub async fn get_application_by_id( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/get_asset_by_id.rs b/crates/algod_client/src/apis/get_asset_by_id.rs index 09eb94a4d..685641f95 100644 --- a/crates/algod_client/src/apis/get_asset_by_id.rs +++ b/crates/algod_client/src/apis/get_asset_by_id.rs @@ -64,7 +64,10 @@ pub async fn get_asset_by_id(http_client: &dyn HttpClient, asset_id: u64) -> Res .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/get_block.rs b/crates/algod_client/src/apis/get_block.rs index 2c8bc54d0..62846370b 100644 --- a/crates/algod_client/src/apis/get_block.rs +++ b/crates/algod_client/src/apis/get_block.rs @@ -74,10 +74,16 @@ pub async fn get_block( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), - ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::MsgPack => serde_path_to_error::deserialize( + &mut rmp_serde::Deserializer::new(std::io::Cursor::new(&response.body)), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::Text => { diff --git a/crates/algod_client/src/apis/get_block_hash.rs b/crates/algod_client/src/apis/get_block_hash.rs index d460be64e..9c2c07e6d 100644 --- a/crates/algod_client/src/apis/get_block_hash.rs +++ b/crates/algod_client/src/apis/get_block_hash.rs @@ -67,7 +67,10 @@ pub async fn get_block_hash( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/get_block_logs.rs b/crates/algod_client/src/apis/get_block_logs.rs index ba7bd6053..83efbb885 100644 --- a/crates/algod_client/src/apis/get_block_logs.rs +++ b/crates/algod_client/src/apis/get_block_logs.rs @@ -66,7 +66,10 @@ pub async fn get_block_logs( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/get_block_time_stamp_offset.rs b/crates/algod_client/src/apis/get_block_time_stamp_offset.rs index 00e8d50ac..981e75437 100644 --- a/crates/algod_client/src/apis/get_block_time_stamp_offset.rs +++ b/crates/algod_client/src/apis/get_block_time_stamp_offset.rs @@ -61,7 +61,10 @@ pub async fn get_block_time_stamp_offset( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/get_block_txids.rs b/crates/algod_client/src/apis/get_block_txids.rs index fa76e97ee..6d3cc5a38 100644 --- a/crates/algod_client/src/apis/get_block_txids.rs +++ b/crates/algod_client/src/apis/get_block_txids.rs @@ -67,7 +67,10 @@ pub async fn get_block_txids( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/get_config.rs b/crates/algod_client/src/apis/get_config.rs index 0faf901e5..41d988a95 100644 --- a/crates/algod_client/src/apis/get_config.rs +++ b/crates/algod_client/src/apis/get_config.rs @@ -57,7 +57,10 @@ pub async fn get_config(http_client: &dyn HttpClient) -> Result { .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/get_debug_settings_prof.rs b/crates/algod_client/src/apis/get_debug_settings_prof.rs index 4472f5d6f..1d136f98e 100644 --- a/crates/algod_client/src/apis/get_debug_settings_prof.rs +++ b/crates/algod_client/src/apis/get_debug_settings_prof.rs @@ -59,7 +59,10 @@ pub async fn get_debug_settings_prof( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/get_genesis.rs b/crates/algod_client/src/apis/get_genesis.rs index 8806f71c0..e5348d1ba 100644 --- a/crates/algod_client/src/apis/get_genesis.rs +++ b/crates/algod_client/src/apis/get_genesis.rs @@ -58,7 +58,10 @@ pub async fn get_genesis(http_client: &dyn HttpClient) -> Result .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/get_ledger_state_delta.rs b/crates/algod_client/src/apis/get_ledger_state_delta.rs index ff4afeb31..fe25c546e 100644 --- a/crates/algod_client/src/apis/get_ledger_state_delta.rs +++ b/crates/algod_client/src/apis/get_ledger_state_delta.rs @@ -70,10 +70,16 @@ pub async fn get_ledger_state_delta( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), - ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::MsgPack => serde_path_to_error::deserialize( + &mut rmp_serde::Deserializer::new(std::io::Cursor::new(&response.body)), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::Text => { diff --git a/crates/algod_client/src/apis/get_ledger_state_delta_for_transaction_group.rs b/crates/algod_client/src/apis/get_ledger_state_delta_for_transaction_group.rs index cf2a5ba01..8255fad57 100644 --- a/crates/algod_client/src/apis/get_ledger_state_delta_for_transaction_group.rs +++ b/crates/algod_client/src/apis/get_ledger_state_delta_for_transaction_group.rs @@ -73,10 +73,16 @@ pub async fn get_ledger_state_delta_for_transaction_group( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), - ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::MsgPack => serde_path_to_error::deserialize( + &mut rmp_serde::Deserializer::new(std::io::Cursor::new(&response.body)), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::Text => { diff --git a/crates/algod_client/src/apis/get_light_block_header_proof.rs b/crates/algod_client/src/apis/get_light_block_header_proof.rs index 518464bb2..e235dc855 100644 --- a/crates/algod_client/src/apis/get_light_block_header_proof.rs +++ b/crates/algod_client/src/apis/get_light_block_header_proof.rs @@ -68,7 +68,10 @@ pub async fn get_light_block_header_proof( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/get_participation_key_by_id.rs b/crates/algod_client/src/apis/get_participation_key_by_id.rs index 6deb16caa..dd4e1ca36 100644 --- a/crates/algod_client/src/apis/get_participation_key_by_id.rs +++ b/crates/algod_client/src/apis/get_participation_key_by_id.rs @@ -70,7 +70,10 @@ pub async fn get_participation_key_by_id( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/get_participation_keys.rs b/crates/algod_client/src/apis/get_participation_keys.rs index 07578a587..535581afe 100644 --- a/crates/algod_client/src/apis/get_participation_keys.rs +++ b/crates/algod_client/src/apis/get_participation_keys.rs @@ -64,7 +64,10 @@ pub async fn get_participation_keys( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/get_pending_transactions.rs b/crates/algod_client/src/apis/get_pending_transactions.rs index c1118f8b0..a046bd8cb 100644 --- a/crates/algod_client/src/apis/get_pending_transactions.rs +++ b/crates/algod_client/src/apis/get_pending_transactions.rs @@ -71,10 +71,16 @@ pub async fn get_pending_transactions( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), - ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::MsgPack => serde_path_to_error::deserialize( + &mut rmp_serde::Deserializer::new(std::io::Cursor::new(&response.body)), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::Text => { diff --git a/crates/algod_client/src/apis/get_pending_transactions_by_address.rs b/crates/algod_client/src/apis/get_pending_transactions_by_address.rs index 0deb96514..826f778f2 100644 --- a/crates/algod_client/src/apis/get_pending_transactions_by_address.rs +++ b/crates/algod_client/src/apis/get_pending_transactions_by_address.rs @@ -77,10 +77,16 @@ pub async fn get_pending_transactions_by_address( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), - ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::MsgPack => serde_path_to_error::deserialize( + &mut rmp_serde::Deserializer::new(std::io::Cursor::new(&response.body)), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::Text => { diff --git a/crates/algod_client/src/apis/get_state_proof.rs b/crates/algod_client/src/apis/get_state_proof.rs index 7c19ca433..a3c25b75a 100644 --- a/crates/algod_client/src/apis/get_state_proof.rs +++ b/crates/algod_client/src/apis/get_state_proof.rs @@ -68,7 +68,10 @@ pub async fn get_state_proof( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/get_status.rs b/crates/algod_client/src/apis/get_status.rs index 5e2107486..206347d85 100644 --- a/crates/algod_client/src/apis/get_status.rs +++ b/crates/algod_client/src/apis/get_status.rs @@ -60,7 +60,10 @@ pub async fn get_status(http_client: &dyn HttpClient) -> Result serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/get_supply.rs b/crates/algod_client/src/apis/get_supply.rs index 5f046f9bd..51ff901fa 100644 --- a/crates/algod_client/src/apis/get_supply.rs +++ b/crates/algod_client/src/apis/get_supply.rs @@ -59,7 +59,10 @@ pub async fn get_supply(http_client: &dyn HttpClient) -> Result serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/get_sync_round.rs b/crates/algod_client/src/apis/get_sync_round.rs index ef55e11ab..b7676dea1 100644 --- a/crates/algod_client/src/apis/get_sync_round.rs +++ b/crates/algod_client/src/apis/get_sync_round.rs @@ -62,7 +62,10 @@ pub async fn get_sync_round(http_client: &dyn HttpClient) -> Result serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/get_transaction_group_ledger_state_deltas_for_round.rs b/crates/algod_client/src/apis/get_transaction_group_ledger_state_deltas_for_round.rs index 5c3247eb7..bb760a603 100644 --- a/crates/algod_client/src/apis/get_transaction_group_ledger_state_deltas_for_round.rs +++ b/crates/algod_client/src/apis/get_transaction_group_ledger_state_deltas_for_round.rs @@ -70,10 +70,16 @@ pub async fn get_transaction_group_ledger_state_deltas_for_round( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), - ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::MsgPack => serde_path_to_error::deserialize( + &mut rmp_serde::Deserializer::new(std::io::Cursor::new(&response.body)), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::Text => { diff --git a/crates/algod_client/src/apis/get_transaction_proof.rs b/crates/algod_client/src/apis/get_transaction_proof.rs index 9e7558e55..2071919ac 100644 --- a/crates/algod_client/src/apis/get_transaction_proof.rs +++ b/crates/algod_client/src/apis/get_transaction_proof.rs @@ -84,7 +84,10 @@ pub async fn get_transaction_proof( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/get_version.rs b/crates/algod_client/src/apis/get_version.rs index 5dcae6e3a..8ecab8efe 100644 --- a/crates/algod_client/src/apis/get_version.rs +++ b/crates/algod_client/src/apis/get_version.rs @@ -57,7 +57,10 @@ pub async fn get_version(http_client: &dyn HttpClient) -> Result .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/pending_transaction_information.rs b/crates/algod_client/src/apis/pending_transaction_information.rs index 9daba2cbc..4f33cb2ef 100644 --- a/crates/algod_client/src/apis/pending_transaction_information.rs +++ b/crates/algod_client/src/apis/pending_transaction_information.rs @@ -76,10 +76,16 @@ pub async fn pending_transaction_information( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), - ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::MsgPack => serde_path_to_error::deserialize( + &mut rmp_serde::Deserializer::new(std::io::Cursor::new(&response.body)), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::Text => { diff --git a/crates/algod_client/src/apis/put_debug_settings_prof.rs b/crates/algod_client/src/apis/put_debug_settings_prof.rs index 5865a137a..89e57a9ca 100644 --- a/crates/algod_client/src/apis/put_debug_settings_prof.rs +++ b/crates/algod_client/src/apis/put_debug_settings_prof.rs @@ -59,7 +59,10 @@ pub async fn put_debug_settings_prof( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/raw_transaction.rs b/crates/algod_client/src/apis/raw_transaction.rs index d6db67f9e..9147e0ea7 100644 --- a/crates/algod_client/src/apis/raw_transaction.rs +++ b/crates/algod_client/src/apis/raw_transaction.rs @@ -72,10 +72,16 @@ pub async fn raw_transaction( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), - ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::MsgPack => serde_path_to_error::deserialize( + &mut rmp_serde::Deserializer::new(std::io::Cursor::new(&response.body)), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::Text => { diff --git a/crates/algod_client/src/apis/shutdown_node.rs b/crates/algod_client/src/apis/shutdown_node.rs index 5daa64a2f..c93be1672 100644 --- a/crates/algod_client/src/apis/shutdown_node.rs +++ b/crates/algod_client/src/apis/shutdown_node.rs @@ -65,7 +65,10 @@ pub async fn shutdown_node( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/simulate_transaction.rs b/crates/algod_client/src/apis/simulate_transaction.rs index 1098ee697..14a68b576 100644 --- a/crates/algod_client/src/apis/simulate_transaction.rs +++ b/crates/algod_client/src/apis/simulate_transaction.rs @@ -99,10 +99,16 @@ pub async fn simulate_transaction( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), - ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::MsgPack => serde_path_to_error::deserialize( + &mut rmp_serde::Deserializer::new(std::io::Cursor::new(&response.body)), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::Text => { diff --git a/crates/algod_client/src/apis/start_catchup.rs b/crates/algod_client/src/apis/start_catchup.rs index 2e2410a75..455af72a6 100644 --- a/crates/algod_client/src/apis/start_catchup.rs +++ b/crates/algod_client/src/apis/start_catchup.rs @@ -75,7 +75,10 @@ pub async fn start_catchup( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/swagger_json.rs b/crates/algod_client/src/apis/swagger_json.rs index 0f3575ec7..2d5a7fd36 100644 --- a/crates/algod_client/src/apis/swagger_json.rs +++ b/crates/algod_client/src/apis/swagger_json.rs @@ -57,7 +57,10 @@ pub async fn swagger_json(http_client: &dyn HttpClient) -> Result .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/teal_compile.rs b/crates/algod_client/src/apis/teal_compile.rs index ae301ad96..ca0e9b28b 100644 --- a/crates/algod_client/src/apis/teal_compile.rs +++ b/crates/algod_client/src/apis/teal_compile.rs @@ -73,7 +73,10 @@ pub async fn teal_compile( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/teal_disassemble.rs b/crates/algod_client/src/apis/teal_disassemble.rs index 444206591..90a9d2071 100644 --- a/crates/algod_client/src/apis/teal_disassemble.rs +++ b/crates/algod_client/src/apis/teal_disassemble.rs @@ -74,10 +74,16 @@ pub async fn teal_disassemble( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), - ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::MsgPack => serde_path_to_error::deserialize( + &mut rmp_serde::Deserializer::new(std::io::Cursor::new(&response.body)), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::Text => { diff --git a/crates/algod_client/src/apis/teal_dryrun.rs b/crates/algod_client/src/apis/teal_dryrun.rs index 15f043893..8aa1addbf 100644 --- a/crates/algod_client/src/apis/teal_dryrun.rs +++ b/crates/algod_client/src/apis/teal_dryrun.rs @@ -77,10 +77,16 @@ pub async fn teal_dryrun( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), - ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::MsgPack => serde_path_to_error::deserialize( + &mut rmp_serde::Deserializer::new(std::io::Cursor::new(&response.body)), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::Text => { diff --git a/crates/algod_client/src/apis/transaction_params.rs b/crates/algod_client/src/apis/transaction_params.rs index bac816555..10ec1bc7a 100644 --- a/crates/algod_client/src/apis/transaction_params.rs +++ b/crates/algod_client/src/apis/transaction_params.rs @@ -61,7 +61,10 @@ pub async fn transaction_params(http_client: &dyn HttpClient) -> Result serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algod_client/src/apis/wait_for_block.rs b/crates/algod_client/src/apis/wait_for_block.rs index 99a77a3bd..205c044fd 100644 --- a/crates/algod_client/src/apis/wait_for_block.rs +++ b/crates/algod_client/src/apis/wait_for_block.rs @@ -67,7 +67,10 @@ pub async fn wait_for_block( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/algokit_abi/Cargo.toml b/crates/algokit_abi/Cargo.toml index 8adab3158..3f26d901b 100644 --- a/crates/algokit_abi/Cargo.toml +++ b/crates/algokit_abi/Cargo.toml @@ -11,6 +11,7 @@ base32 = { workspace = true } sha2 = { workspace = true } serde = { version = "1.0.216", features = ["derive"] } serde_json = "1.0.133" +serde_path_to_error = "0.1" base64 = "0.21" algokit_test_artifacts = { path = "../algokit_test_artifacts" } diff --git a/crates/algokit_abi/src/arc56_contract.rs b/crates/algokit_abi/src/arc56_contract.rs index 7d31e1230..1e1adf8b9 100644 --- a/crates/algokit_abi/src/arc56_contract.rs +++ b/crates/algokit_abi/src/arc56_contract.rs @@ -496,9 +496,11 @@ pub struct Arc56Contract { impl Arc56Contract { /// Create Arc56Contract from JSON string pub fn from_json(json_str: &str) -> Result { - serde_json::from_str(json_str).map_err(|e| ABIError::ValidationError { - message: format!("Failed to parse ARC-56 JSON: {}", e), - }) + serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_str(json_str)).map_err( + |e| ABIError::ValidationError { + message: format!("Failed to parse ARC-56 JSON: {}", e), + }, + ) } /// Convert Arc56Contract to JSON string with optional indentation diff --git a/crates/algokit_transact/Cargo.toml b/crates/algokit_transact/Cargo.toml index 5300807db..49fdf2d5a 100644 --- a/crates/algokit_transact/Cargo.toml +++ b/crates/algokit_transact/Cargo.toml @@ -22,6 +22,7 @@ rmpv = { version = "1.3.0", features = ["with-serde"] } serde = { version = "1.0.216", features = ["derive"] } serde_bytes = "0.11.12" serde_json = "1.0.133" +serde_path_to_error = "0.1" serde_repr = "0.1.20" serde_with = "3.11.0" sha2 = { workspace = true } diff --git a/crates/algokit_transact/src/error.rs b/crates/algokit_transact/src/error.rs index f69db83b7..14bdfae33 100644 --- a/crates/algokit_transact/src/error.rs +++ b/crates/algokit_transact/src/error.rs @@ -12,17 +12,17 @@ use snafu::Snafu; /// manipulating, serializing, or deserializing Algorand transactions. #[derive(Debug, Snafu)] pub enum AlgoKitTransactError { - #[snafu(display("Error ocurred during encoding: {source}"))] + #[snafu(display("Error occurred during encoding: {source}"))] EncodingError { source: rmp_serde::encode::Error }, - #[snafu(display("Error ocurred during decoding: {source}"))] - DecodingError { source: rmp_serde::decode::Error }, - - #[snafu(display("Error ocurred during msgpack encoding: {source}"))] + #[snafu(display("Error occurred during msgpack encoding: {source}"))] MsgpackEncodingError { source: rmpv::encode::Error }, - #[snafu(display("Error ocurred during msgpack decoding: {source}"))] - MsgpackDecodingError { source: rmpv::decode::Error }, + #[snafu(display("Error occurred during decoding at path {path}: {source}"))] + DecodingError { + path: String, + source: rmp_serde::decode::Error, + }, #[snafu(display("Unknown transaction type: {message}"))] UnknownTransactionType { message: String }, @@ -43,20 +43,17 @@ impl From for AlgoKitTransactError { } } -impl From for AlgoKitTransactError { - fn from(source: rmp_serde::decode::Error) -> Self { - AlgoKitTransactError::DecodingError { source } - } -} - impl From for AlgoKitTransactError { fn from(source: rmpv::encode::Error) -> Self { AlgoKitTransactError::MsgpackEncodingError { source } } } -impl From for AlgoKitTransactError { - fn from(source: rmpv::decode::Error) -> Self { - AlgoKitTransactError::MsgpackDecodingError { source } +impl From> for AlgoKitTransactError { + fn from(err: serde_path_to_error::Error) -> Self { + AlgoKitTransactError::DecodingError { + path: err.path().to_string(), + source: err.into_inner(), + } } } diff --git a/crates/algokit_transact/src/traits.rs b/crates/algokit_transact/src/traits.rs index 9d278cfc4..17c45fcc2 100644 --- a/crates/algokit_transact/src/traits.rs +++ b/crates/algokit_transact/src/traits.rs @@ -39,12 +39,14 @@ pub trait AlgorandMsgpack: Serialize + for<'de> Deserialize<'de> { self.serialize(&mut temp_serializer)?; // Deserialize into a Value and sort recursively - let value = rmpv::decode::read_value(&mut temp_buf.as_slice())?; + let value = rmpv::decode::read_value(&mut temp_buf.as_slice()) + .expect("value that was just serialized should deserialize"); let sorted_value = sort_msgpack_value(value)?; // Serialize the sorted value let mut final_buf = Vec::new(); - rmpv::encode::write_value(&mut final_buf, &sorted_value)?; + rmpv::encode::write_value(&mut final_buf, &sorted_value) + .expect("value that was just sorted should serialize"); Ok(final_buf) } @@ -74,9 +76,13 @@ pub trait AlgorandMsgpack: Serialize + for<'de> Deserialize<'de> { && &bytes[..Self::PREFIX.len()] == Self::PREFIX { let without_prefix = &bytes[Self::PREFIX.len()..]; - Ok(rmp_serde::from_slice(without_prefix)?) + Ok(serde_path_to_error::deserialize( + &mut rmp_serde::Deserializer::new(std::io::Cursor::new(without_prefix)), + )?) } else { - Ok(rmp_serde::from_slice(bytes)?) + Ok(serde_path_to_error::deserialize( + &mut rmp_serde::Deserializer::new(std::io::Cursor::new(bytes)), + )?) } } diff --git a/crates/algokit_transact/src/transactions/mod.rs b/crates/algokit_transact/src/transactions/mod.rs index cd3370f17..89bf7d649 100644 --- a/crates/algokit_transact/src/transactions/mod.rs +++ b/crates/algokit_transact/src/transactions/mod.rs @@ -209,7 +209,9 @@ impl AlgorandMsgpack for SignedTransaction { // decode the transaction using Transaction::decode (which does check the type) and // then add it to the decoded struct fn decode(bytes: &[u8]) -> Result { - let value: rmpv::Value = rmp_serde::from_slice(bytes)?; + let value: rmpv::Value = serde_path_to_error::deserialize( + &mut rmp_serde::Deserializer::new(std::io::Cursor::new(bytes)), + )?; match value { rmpv::Value::Map(map) => { @@ -224,7 +226,9 @@ impl AlgorandMsgpack for SignedTransaction { let stxn = SignedTransaction { transaction: Transaction::decode(&txn_buf)?, - ..rmp_serde::from_slice(bytes)? + ..serde_path_to_error::deserialize(&mut rmp_serde::Deserializer::new( + std::io::Cursor::new(bytes), + ))? }; Ok(stxn) diff --git a/crates/algokit_transact_ffi/src/lib.rs b/crates/algokit_transact_ffi/src/lib.rs index b0a3d0041..a9c122298 100644 --- a/crates/algokit_transact_ffi/src/lib.rs +++ b/crates/algokit_transact_ffi/src/lib.rs @@ -49,11 +49,6 @@ impl From for AlgoKitTransactError { message: e.to_string(), } } - algokit_transact::AlgoKitTransactError::MsgpackDecodingError { .. } => { - AlgoKitTransactError::DecodingError { - message: e.to_string(), - } - } algokit_transact::AlgoKitTransactError::MsgpackEncodingError { .. } => { AlgoKitTransactError::EncodingError { message: e.to_string(), diff --git a/crates/indexer_client/Cargo.toml b/crates/indexer_client/Cargo.toml index feac837bd..b5c2fbfa9 100644 --- a/crates/indexer_client/Cargo.toml +++ b/crates/indexer_client/Cargo.toml @@ -20,6 +20,7 @@ serde_with = { version = "^3.8", default-features = false, features = [ "macros", ] } serde_json = "^1.0" +serde_path_to_error = "^0.1" serde_repr = "^0.1" serde_bytes = "^0.11" diff --git a/crates/indexer_client/src/apis/lookup_account_app_local_states.rs b/crates/indexer_client/src/apis/lookup_account_app_local_states.rs index 876b5872f..5671c9713 100644 --- a/crates/indexer_client/src/apis/lookup_account_app_local_states.rs +++ b/crates/indexer_client/src/apis/lookup_account_app_local_states.rs @@ -87,7 +87,10 @@ pub async fn lookup_account_app_local_states( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/indexer_client/src/apis/lookup_account_assets.rs b/crates/indexer_client/src/apis/lookup_account_assets.rs index 29f6372b8..bcf507a50 100644 --- a/crates/indexer_client/src/apis/lookup_account_assets.rs +++ b/crates/indexer_client/src/apis/lookup_account_assets.rs @@ -87,7 +87,10 @@ pub async fn lookup_account_assets( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/indexer_client/src/apis/lookup_account_by_id.rs b/crates/indexer_client/src/apis/lookup_account_by_id.rs index a516345cb..b33800037 100644 --- a/crates/indexer_client/src/apis/lookup_account_by_id.rs +++ b/crates/indexer_client/src/apis/lookup_account_by_id.rs @@ -82,7 +82,10 @@ pub async fn lookup_account_by_id( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/indexer_client/src/apis/lookup_account_created_applications.rs b/crates/indexer_client/src/apis/lookup_account_created_applications.rs index 740351ec7..156ccd7fd 100644 --- a/crates/indexer_client/src/apis/lookup_account_created_applications.rs +++ b/crates/indexer_client/src/apis/lookup_account_created_applications.rs @@ -87,7 +87,10 @@ pub async fn lookup_account_created_applications( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/indexer_client/src/apis/lookup_account_created_assets.rs b/crates/indexer_client/src/apis/lookup_account_created_assets.rs index 4ff954d08..14b6f6162 100644 --- a/crates/indexer_client/src/apis/lookup_account_created_assets.rs +++ b/crates/indexer_client/src/apis/lookup_account_created_assets.rs @@ -87,7 +87,10 @@ pub async fn lookup_account_created_assets( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/indexer_client/src/apis/lookup_account_transactions.rs b/crates/indexer_client/src/apis/lookup_account_transactions.rs index 27b699602..d502aa4a4 100644 --- a/crates/indexer_client/src/apis/lookup_account_transactions.rs +++ b/crates/indexer_client/src/apis/lookup_account_transactions.rs @@ -142,7 +142,10 @@ pub async fn lookup_account_transactions( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/indexer_client/src/apis/lookup_application_box_by_id_and_name.rs b/crates/indexer_client/src/apis/lookup_application_box_by_id_and_name.rs index 10f3ec345..eecabf46c 100644 --- a/crates/indexer_client/src/apis/lookup_application_box_by_id_and_name.rs +++ b/crates/indexer_client/src/apis/lookup_application_box_by_id_and_name.rs @@ -70,7 +70,10 @@ pub async fn lookup_application_box_by_id_and_name( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/indexer_client/src/apis/lookup_application_by_id.rs b/crates/indexer_client/src/apis/lookup_application_by_id.rs index 5f058e42a..bdc42a1e9 100644 --- a/crates/indexer_client/src/apis/lookup_application_by_id.rs +++ b/crates/indexer_client/src/apis/lookup_application_by_id.rs @@ -71,7 +71,10 @@ pub async fn lookup_application_by_id( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/indexer_client/src/apis/lookup_application_logs_by_id.rs b/crates/indexer_client/src/apis/lookup_application_logs_by_id.rs index 0ac7eaed6..b72c6d89c 100644 --- a/crates/indexer_client/src/apis/lookup_application_logs_by_id.rs +++ b/crates/indexer_client/src/apis/lookup_application_logs_by_id.rs @@ -94,7 +94,10 @@ pub async fn lookup_application_logs_by_id( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/indexer_client/src/apis/lookup_asset_balances.rs b/crates/indexer_client/src/apis/lookup_asset_balances.rs index db5829485..cd3a25007 100644 --- a/crates/indexer_client/src/apis/lookup_asset_balances.rs +++ b/crates/indexer_client/src/apis/lookup_asset_balances.rs @@ -88,7 +88,10 @@ pub async fn lookup_asset_balances( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/indexer_client/src/apis/lookup_asset_by_id.rs b/crates/indexer_client/src/apis/lookup_asset_by_id.rs index 6f413d0ec..c515604d8 100644 --- a/crates/indexer_client/src/apis/lookup_asset_by_id.rs +++ b/crates/indexer_client/src/apis/lookup_asset_by_id.rs @@ -69,7 +69,10 @@ pub async fn lookup_asset_by_id( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/indexer_client/src/apis/lookup_asset_transactions.rs b/crates/indexer_client/src/apis/lookup_asset_transactions.rs index b6ca1d39d..2865ece59 100644 --- a/crates/indexer_client/src/apis/lookup_asset_transactions.rs +++ b/crates/indexer_client/src/apis/lookup_asset_transactions.rs @@ -149,7 +149,10 @@ pub async fn lookup_asset_transactions( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/indexer_client/src/apis/lookup_block.rs b/crates/indexer_client/src/apis/lookup_block.rs index da5649b6e..923412cb3 100644 --- a/crates/indexer_client/src/apis/lookup_block.rs +++ b/crates/indexer_client/src/apis/lookup_block.rs @@ -68,7 +68,10 @@ pub async fn lookup_block( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/indexer_client/src/apis/lookup_transaction.rs b/crates/indexer_client/src/apis/lookup_transaction.rs index 1125bb730..52c6f5913 100644 --- a/crates/indexer_client/src/apis/lookup_transaction.rs +++ b/crates/indexer_client/src/apis/lookup_transaction.rs @@ -67,7 +67,10 @@ pub async fn lookup_transaction( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/indexer_client/src/apis/make_health_check.rs b/crates/indexer_client/src/apis/make_health_check.rs index bb9c9a1dc..b098f5652 100644 --- a/crates/indexer_client/src/apis/make_health_check.rs +++ b/crates/indexer_client/src/apis/make_health_check.rs @@ -57,7 +57,10 @@ pub async fn make_health_check(http_client: &dyn HttpClient) -> Result serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/indexer_client/src/apis/search_for_accounts.rs b/crates/indexer_client/src/apis/search_for_accounts.rs index bc8bac436..55463d0e5 100644 --- a/crates/indexer_client/src/apis/search_for_accounts.rs +++ b/crates/indexer_client/src/apis/search_for_accounts.rs @@ -116,7 +116,10 @@ pub async fn search_for_accounts( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/indexer_client/src/apis/search_for_application_boxes.rs b/crates/indexer_client/src/apis/search_for_application_boxes.rs index f33cc740c..969b57dca 100644 --- a/crates/indexer_client/src/apis/search_for_application_boxes.rs +++ b/crates/indexer_client/src/apis/search_for_application_boxes.rs @@ -77,7 +77,10 @@ pub async fn search_for_application_boxes( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/indexer_client/src/apis/search_for_applications.rs b/crates/indexer_client/src/apis/search_for_applications.rs index 23189913b..74637669e 100644 --- a/crates/indexer_client/src/apis/search_for_applications.rs +++ b/crates/indexer_client/src/apis/search_for_applications.rs @@ -85,7 +85,10 @@ pub async fn search_for_applications( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/indexer_client/src/apis/search_for_assets.rs b/crates/indexer_client/src/apis/search_for_assets.rs index e26ac5f3a..587bce412 100644 --- a/crates/indexer_client/src/apis/search_for_assets.rs +++ b/crates/indexer_client/src/apis/search_for_assets.rs @@ -96,7 +96,10 @@ pub async fn search_for_assets( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/indexer_client/src/apis/search_for_block_headers.rs b/crates/indexer_client/src/apis/search_for_block_headers.rs index bf1bdc707..d95a1ca51 100644 --- a/crates/indexer_client/src/apis/search_for_block_headers.rs +++ b/crates/indexer_client/src/apis/search_for_block_headers.rs @@ -106,7 +106,10 @@ pub async fn search_for_block_headers( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/indexer_client/src/apis/search_for_transactions.rs b/crates/indexer_client/src/apis/search_for_transactions.rs index 655f5bbf5..bd63729b4 100644 --- a/crates/indexer_client/src/apis/search_for_transactions.rs +++ b/crates/indexer_client/src/apis/search_for_transactions.rs @@ -162,7 +162,10 @@ pub async fn search_for_transactions( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/kmd_client/Cargo.toml b/crates/kmd_client/Cargo.toml index 347490f27..96d5acde3 100644 --- a/crates/kmd_client/Cargo.toml +++ b/crates/kmd_client/Cargo.toml @@ -20,6 +20,7 @@ serde_with = { version = "^3.8", default-features = false, features = [ "macros", ] } serde_json = "^1.0" +serde_path_to_error = "^0.1" serde_repr = "^0.1" serde_bytes = "^0.11" diff --git a/crates/kmd_client/src/apis/create_wallet.rs b/crates/kmd_client/src/apis/create_wallet.rs index 2f9631f1c..051d571a7 100644 --- a/crates/kmd_client/src/apis/create_wallet.rs +++ b/crates/kmd_client/src/apis/create_wallet.rs @@ -66,7 +66,10 @@ pub async fn create_wallet( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/kmd_client/src/apis/delete_key.rs b/crates/kmd_client/src/apis/delete_key.rs index d2018637d..a575ce465 100644 --- a/crates/kmd_client/src/apis/delete_key.rs +++ b/crates/kmd_client/src/apis/delete_key.rs @@ -58,7 +58,10 @@ pub async fn delete_key(http_client: &dyn HttpClient) -> Result serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/kmd_client/src/apis/delete_multisig.rs b/crates/kmd_client/src/apis/delete_multisig.rs index 4b2d99766..da20eb6ef 100644 --- a/crates/kmd_client/src/apis/delete_multisig.rs +++ b/crates/kmd_client/src/apis/delete_multisig.rs @@ -60,7 +60,10 @@ pub async fn delete_multisig( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/kmd_client/src/apis/export_key.rs b/crates/kmd_client/src/apis/export_key.rs index c3deb52a5..f88c994e0 100644 --- a/crates/kmd_client/src/apis/export_key.rs +++ b/crates/kmd_client/src/apis/export_key.rs @@ -66,7 +66,10 @@ pub async fn export_key( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/kmd_client/src/apis/export_master_key.rs b/crates/kmd_client/src/apis/export_master_key.rs index ccdf10647..ccc9b9c03 100644 --- a/crates/kmd_client/src/apis/export_master_key.rs +++ b/crates/kmd_client/src/apis/export_master_key.rs @@ -66,7 +66,10 @@ pub async fn export_master_key( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/kmd_client/src/apis/export_multisig.rs b/crates/kmd_client/src/apis/export_multisig.rs index 2e8a47d44..26c0611cf 100644 --- a/crates/kmd_client/src/apis/export_multisig.rs +++ b/crates/kmd_client/src/apis/export_multisig.rs @@ -66,7 +66,10 @@ pub async fn export_multisig( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/kmd_client/src/apis/generate_key.rs b/crates/kmd_client/src/apis/generate_key.rs index 58fcda832..fc28afeed 100644 --- a/crates/kmd_client/src/apis/generate_key.rs +++ b/crates/kmd_client/src/apis/generate_key.rs @@ -66,7 +66,10 @@ pub async fn generate_key( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/kmd_client/src/apis/get_version.rs b/crates/kmd_client/src/apis/get_version.rs index 1eadf748f..96a6d0151 100644 --- a/crates/kmd_client/src/apis/get_version.rs +++ b/crates/kmd_client/src/apis/get_version.rs @@ -58,7 +58,10 @@ pub async fn get_version(http_client: &dyn HttpClient) -> Result serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/kmd_client/src/apis/get_wallet_info.rs b/crates/kmd_client/src/apis/get_wallet_info.rs index 340f60088..8dc3a463f 100644 --- a/crates/kmd_client/src/apis/get_wallet_info.rs +++ b/crates/kmd_client/src/apis/get_wallet_info.rs @@ -66,7 +66,10 @@ pub async fn get_wallet_info( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/kmd_client/src/apis/import_key.rs b/crates/kmd_client/src/apis/import_key.rs index 0984383d6..dec8e15c8 100644 --- a/crates/kmd_client/src/apis/import_key.rs +++ b/crates/kmd_client/src/apis/import_key.rs @@ -66,7 +66,10 @@ pub async fn import_key( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/kmd_client/src/apis/import_multisig.rs b/crates/kmd_client/src/apis/import_multisig.rs index 7eb86a13c..ef4cd484d 100644 --- a/crates/kmd_client/src/apis/import_multisig.rs +++ b/crates/kmd_client/src/apis/import_multisig.rs @@ -66,7 +66,10 @@ pub async fn import_multisig( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/kmd_client/src/apis/init_wallet_handle_token.rs b/crates/kmd_client/src/apis/init_wallet_handle_token.rs index 1588ac583..d0c143e97 100644 --- a/crates/kmd_client/src/apis/init_wallet_handle_token.rs +++ b/crates/kmd_client/src/apis/init_wallet_handle_token.rs @@ -66,7 +66,10 @@ pub async fn init_wallet_handle_token( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/kmd_client/src/apis/list_keys_in_wallet.rs b/crates/kmd_client/src/apis/list_keys_in_wallet.rs index cde78aaa0..c89d18f11 100644 --- a/crates/kmd_client/src/apis/list_keys_in_wallet.rs +++ b/crates/kmd_client/src/apis/list_keys_in_wallet.rs @@ -66,7 +66,10 @@ pub async fn list_keys_in_wallet( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/kmd_client/src/apis/list_multisg.rs b/crates/kmd_client/src/apis/list_multisg.rs index a1cbce03b..2ec4211b1 100644 --- a/crates/kmd_client/src/apis/list_multisg.rs +++ b/crates/kmd_client/src/apis/list_multisg.rs @@ -66,7 +66,10 @@ pub async fn list_multisg( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/kmd_client/src/apis/list_wallets.rs b/crates/kmd_client/src/apis/list_wallets.rs index 1203dc484..50c5eab88 100644 --- a/crates/kmd_client/src/apis/list_wallets.rs +++ b/crates/kmd_client/src/apis/list_wallets.rs @@ -58,7 +58,10 @@ pub async fn list_wallets(http_client: &dyn HttpClient) -> Result serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/kmd_client/src/apis/release_wallet_handle_token.rs b/crates/kmd_client/src/apis/release_wallet_handle_token.rs index e40a2bead..6bb1fc7b1 100644 --- a/crates/kmd_client/src/apis/release_wallet_handle_token.rs +++ b/crates/kmd_client/src/apis/release_wallet_handle_token.rs @@ -66,7 +66,10 @@ pub async fn release_wallet_handle_token( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/kmd_client/src/apis/rename_wallet.rs b/crates/kmd_client/src/apis/rename_wallet.rs index eda7ec6f0..3fa239e83 100644 --- a/crates/kmd_client/src/apis/rename_wallet.rs +++ b/crates/kmd_client/src/apis/rename_wallet.rs @@ -66,7 +66,10 @@ pub async fn rename_wallet( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/kmd_client/src/apis/renew_wallet_handle_token.rs b/crates/kmd_client/src/apis/renew_wallet_handle_token.rs index 2568967ab..c51395da7 100644 --- a/crates/kmd_client/src/apis/renew_wallet_handle_token.rs +++ b/crates/kmd_client/src/apis/renew_wallet_handle_token.rs @@ -66,7 +66,10 @@ pub async fn renew_wallet_handle_token( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/kmd_client/src/apis/sign_multisig_program.rs b/crates/kmd_client/src/apis/sign_multisig_program.rs index 8e19814d9..6ee2fa9c6 100644 --- a/crates/kmd_client/src/apis/sign_multisig_program.rs +++ b/crates/kmd_client/src/apis/sign_multisig_program.rs @@ -66,7 +66,10 @@ pub async fn sign_multisig_program( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/kmd_client/src/apis/sign_multisig_transaction.rs b/crates/kmd_client/src/apis/sign_multisig_transaction.rs index f421e8ae3..d2914403b 100644 --- a/crates/kmd_client/src/apis/sign_multisig_transaction.rs +++ b/crates/kmd_client/src/apis/sign_multisig_transaction.rs @@ -66,7 +66,10 @@ pub async fn sign_multisig_transaction( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/kmd_client/src/apis/sign_program.rs b/crates/kmd_client/src/apis/sign_program.rs index 61eba6b8e..c027ea109 100644 --- a/crates/kmd_client/src/apis/sign_program.rs +++ b/crates/kmd_client/src/apis/sign_program.rs @@ -66,7 +66,10 @@ pub async fn sign_program( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/kmd_client/src/apis/sign_transaction.rs b/crates/kmd_client/src/apis/sign_transaction.rs index 5c5cb0e2f..4927d0008 100644 --- a/crates/kmd_client/src/apis/sign_transaction.rs +++ b/crates/kmd_client/src/apis/sign_transaction.rs @@ -66,7 +66,10 @@ pub async fn sign_transaction( .unwrap_or("application/json"); match ContentType::from(content_type) { - ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde { diff --git a/crates/kmd_client/src/apis/swagger_handler.rs b/crates/kmd_client/src/apis/swagger_handler.rs index 46e258ab6..272dc26c5 100644 --- a/crates/kmd_client/src/apis/swagger_handler.rs +++ b/crates/kmd_client/src/apis/swagger_handler.rs @@ -57,7 +57,10 @@ pub async fn swagger_handler(http_client: &dyn HttpClient) -> Result serde_json::from_slice(&response.body).map_err(|e| Error::Serde { + ContentType::Json => serde_path_to_error::deserialize( + &mut serde_json::Deserializer::from_slice(&response.body), + ) + .map_err(|e| Error::Serde { message: e.to_string(), }), ContentType::MsgPack => Err(Error::Serde {