Skip to content

Commit f12513c

Browse files
committed
feat: use serde_path_to_error
1 parent 1aa238d commit f12513c

File tree

103 files changed

+460
-112
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+460
-112
lines changed

Cargo.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/oas_generator/rust_oas_generator/templates/apis/api.rs.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub async fn {{ operation.rust_function_name }}(
100100
match content_type {
101101
ContentType::Json => {
102102
let content = resp.text().await?;
103-
serde_json::from_str(&content).map_err(Error::from)
103+
serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_str(&content)).map_err(Error::from)
104104
},
105105
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) }}`"))),
106106
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) }}`")))),

api/oas_generator/rust_oas_generator/templates/apis/endpoint.rs.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ pub async fn {{ operation.rust_function_name }}(
208208
.unwrap_or("application/json");
209209

210210
match ContentType::from(content_type) {
211-
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { message: e.to_string() }),
211+
ContentType::Json => serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_slice(&response.body)).map_err(|e| Error::Serde { message: e.to_string() }),
212212
{% if operation.supports_msgpack %}
213-
ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde { message: e.to_string() }),
213+
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() }),
214214
{% else %}
215215
ContentType::MsgPack => Err(Error::Serde { message: "MsgPack not supported".to_string() }),
216216
{% endif %}

api/oas_generator/rust_oas_generator/templates/base/Cargo.toml.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ serde_with = { version = "^3.8", default-features = false, features = [
2020
"macros",
2121
] }
2222
serde_json = "^1.0"
23+
serde_path_to_error = "^0.1"
2324
serde_repr = "^0.1"
2425
serde_bytes = "^0.11"
2526

crates/algod_client/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ serde_with = { version = "^3.8", default-features = false, features = [
2020
"macros",
2121
] }
2222
serde_json = "^1.0"
23+
serde_path_to_error = "^0.1"
2324
serde_repr = "^0.1"
2425
serde_bytes = "^0.11"
2526

crates/algod_client/src/apis/abort_catchup.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ pub async fn abort_catchup(
6969
.unwrap_or("application/json");
7070

7171
match ContentType::from(content_type) {
72-
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
72+
ContentType::Json => serde_path_to_error::deserialize(
73+
&mut serde_json::Deserializer::from_slice(&response.body),
74+
)
75+
.map_err(|e| Error::Serde {
7376
message: e.to_string(),
7477
}),
7578
ContentType::MsgPack => Err(Error::Serde {

crates/algod_client/src/apis/account_application_information.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,16 @@ pub async fn account_application_information(
8585
.unwrap_or("application/json");
8686

8787
match ContentType::from(content_type) {
88-
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
88+
ContentType::Json => serde_path_to_error::deserialize(
89+
&mut serde_json::Deserializer::from_slice(&response.body),
90+
)
91+
.map_err(|e| Error::Serde {
8992
message: e.to_string(),
9093
}),
91-
ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde {
94+
ContentType::MsgPack => serde_path_to_error::deserialize(
95+
&mut rmp_serde::Deserializer::new(std::io::Cursor::new(&response.body)),
96+
)
97+
.map_err(|e| Error::Serde {
9298
message: e.to_string(),
9399
}),
94100
ContentType::Text => {

crates/algod_client/src/apis/account_asset_information.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ pub async fn account_asset_information(
7272
.unwrap_or("application/json");
7373

7474
match ContentType::from(content_type) {
75-
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
75+
ContentType::Json => serde_path_to_error::deserialize(
76+
&mut serde_json::Deserializer::from_slice(&response.body),
77+
)
78+
.map_err(|e| Error::Serde {
7679
message: e.to_string(),
7780
}),
7881
ContentType::MsgPack => Err(Error::Serde {

crates/algod_client/src/apis/account_assets_information.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ pub async fn account_assets_information(
7979
.unwrap_or("application/json");
8080

8181
match ContentType::from(content_type) {
82-
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
82+
ContentType::Json => serde_path_to_error::deserialize(
83+
&mut serde_json::Deserializer::from_slice(&response.body),
84+
)
85+
.map_err(|e| Error::Serde {
8386
message: e.to_string(),
8487
}),
8588
ContentType::MsgPack => Err(Error::Serde {

crates/algod_client/src/apis/account_information.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ pub async fn account_information(
7575
.unwrap_or("application/json");
7676

7777
match ContentType::from(content_type) {
78-
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
78+
ContentType::Json => serde_path_to_error::deserialize(
79+
&mut serde_json::Deserializer::from_slice(&response.body),
80+
)
81+
.map_err(|e| Error::Serde {
7982
message: e.to_string(),
8083
}),
8184
ContentType::MsgPack => Err(Error::Serde {

0 commit comments

Comments
 (0)