Skip to content

Commit

Permalink
Fix status details
Browse files Browse the repository at this point in the history
  • Loading branch information
tinrab committed Feb 6, 2024
1 parent 256d718 commit f10228e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
36 changes: 23 additions & 13 deletions bomboni_proto/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,13 @@ fn build_serde(config: &mut Config) {
".google.rpc.Status",
r"#[derive(::serde::Serialize, ::serde::Deserialize)]",
);

config.field_attribute(
".google.rpc.Status.details",
r#"#[serde(with = "crate::google::rpc::status::details_serde")]"#,
);
config.field_attribute(
".google.rpc.Status.code",
r#"#[serde(with = "crate::google::rpc::helpers::code_serde")]"#,
);
config.field_attribute(
".tools.Status",
r#"#[serde(with = "crate::tools::helpers::status_serde")]"#,
);
config.field_attribute(
".tools.CommandResponse.Status",
r#"#[serde(with = "crate::tools::helpers::command_response::status_serde")]"#,
".google.rpc.Status.details",
r#"#[serde(with = "crate::rpc::status::details_serde")]"#,
);
}

Expand All @@ -149,7 +140,7 @@ fn get_copy_type_paths() -> impl Iterator<Item = String> {

#[cfg(feature = "wasm")]
fn build_wasm(config: &mut Config) {
for type_name in [
let error_details = [
"Status",
"RetryInfo",
"DebugInfo",
Expand All @@ -161,7 +152,8 @@ fn build_wasm(config: &mut Config) {
"ResourceInfo",
"Help",
"LocalizedMessage",
] {
];
for type_name in &error_details {
config.type_attribute(
format!(".google.rpc.{type_name}"),
r"
Expand All @@ -170,4 +162,22 @@ fn build_wasm(config: &mut Config) {
",
);
}
config.field_attribute(
".google.rpc.Status.code",
"#[wasm(override_type = \"string\")]",
);
config.field_attribute(
".google.rpc.Status.details",
format!(
"#[wasm(override_type = \"(\n{})[]\")]",
error_details
.iter()
.skip(1)
.map(|type_name| format!(
" ( {{'@type': 'type.googleapis.com/google.rpc.{type_name}';}} & ({type_name}) )\n"
))
.collect::<Vec<_>>()
.join(" | ")
),
);
}
2 changes: 1 addition & 1 deletion bomboni_proto/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod protobuf;
mod rpc;
pub mod rpc;
pub mod serde;

/// Includes generated protobuf code.
Expand Down
1 change: 1 addition & 0 deletions bomboni_proto/src/protobuf/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ macro_rules! impl_proto_any_seq_serde {
$any_serde::serialize(self.0, serializer)
}
}

let mut seq = serializer.serialize_seq(Some(details.len()))?;
for detail in details {
seq.serialize_element(&Proxy(detail))?;
Expand Down
3 changes: 3 additions & 0 deletions bomboni_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ bomboni_wasm_derive = { path = "../bomboni_wasm_derive", version = "0.1.54", opt
[dev-dependencies]
serde = { version = "1.0.196", features = ["derive"] }
serde_json = "1.0.113"
bomboni_proto = { path = "../bomboni_proto", features = [
"wasm",
], version = "0.1.54" }
2 changes: 1 addition & 1 deletion bomboni_wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub trait Wasm {
#[cfg(feature = "derive")]
pub use bomboni_wasm_derive::*;

#[cfg(test)]
#[cfg(all(test, feature = "derive"))]
mod tests {
use super::*;
use serde::{Deserialize, Serialize};
Expand Down

0 comments on commit f10228e

Please sign in to comment.