Skip to content

Commit

Permalink
chore(rs-bindgen): improve serve logging and error handling
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
  • Loading branch information
rvolosatovs committed Jul 5, 2024
1 parent 74c932b commit 0f97412
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 14 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ wasmtime = { version = "22", default-features = false }
wasmtime-wasi = { version = "22", default-features = false }
wit-bindgen = { version = "0.27", default-features = false }
wit-bindgen-core = { version = "0.27", default-features = false }
wit-bindgen-wrpc = { version = "0.4.1", default-features = false, path = "./crates/wit-bindgen" }
wit-bindgen-wrpc = { version = "0.4.2", default-features = false, path = "./crates/wit-bindgen" }
wit-bindgen-wrpc-go = { version = "0.2", default-features = false, path = "./crates/wit-bindgen-go" }
wit-bindgen-wrpc-rust = { version = "0.4.1", default-features = false, path = "./crates/wit-bindgen-rust" }
wit-bindgen-wrpc-rust-macro = { version = "0.4", default-features = false, path = "./crates/wit-bindgen-rust-macro" }
wit-bindgen-wrpc-rust = { version = "0.4.2", default-features = false, path = "./crates/wit-bindgen-rust" }
wit-bindgen-wrpc-rust-macro = { version = "0.4.2", default-features = false, path = "./crates/wit-bindgen-rust-macro" }
wit-component = { version = "0.212", default-features = false }
wit-parser = { version = "0.212", default-features = false }
wrpc-cli = { version = "0.2", path = "./crates/cli", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion crates/wit-bindgen-rust-macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wit-bindgen-wrpc-rust-macro"
version = "0.4.0"
version = "0.4.2"
description = """
Procedural macro paired with the `wit-bindgen-wrpc` crate.
"""
Expand Down
2 changes: 1 addition & 1 deletion crates/wit-bindgen-rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wit-bindgen-wrpc-rust"
version = "0.4.1"
version = "0.4.2"
description = """
Rust bindings generator for wRPC, typically used through
the `wit-bindgen-wrpc` crate's `generate!` macro.
Expand Down
17 changes: 12 additions & 5 deletions crates/wit-bindgen-rust/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,11 @@ pub async fn serve_interface<T: {wrpc_transport}::Serve, U>(
self.src,
r#"
let rx = rx.map({tracing}::Instrument::in_current_span).map({tokio}::spawn);
{tracing}::trace!(instance = "{instance}", func = "{wit_name}", "calling handler");
match {trait_name}::{name}(&handler, cx"#,
tokio = self.gen.tokio_path(),
tracing = self.gen.tracing_path(),
wit_name = func.name,
);
for i in 0..func.params.len() {
uwrite!(self.src, ", p{i}");
Expand All @@ -352,8 +354,12 @@ pub async fn serve_interface<T: {wrpc_transport}::Serve, U>(
).await {{
Ok(()) => {{
if let Some(rx) = rx {{
if let Err(err) = rx.await? {{
{tracing}::warn!(?err, "failed to receive async `{instance}.{wit_name}` invocation parameters");
{tracing}::trace!(instance = "{instance}", func = "{wit_name}", "receiving async invocation parameters");
if let Err(err) = {anyhow}::Context::context(
rx.await,
"receipt of async `.{wit_name}` invocation parameters failed",
)? {{
{tracing}::warn!(?err, instance = "{instance}", func = "{wit_name}", "failed to receive async invocation parameters");
}}
}}
continue;
Expand All @@ -362,22 +368,23 @@ pub async fn serve_interface<T: {wrpc_transport}::Serve, U>(
if let Some(rx) = rx {{
rx.abort();
}}
{tracing}::warn!(?err, "failed to transmit `{instance}.{wit_name}` invocation results");
{tracing}::warn!(?err, instance = "{instance}", func = "{wit_name}", "failed to transmit invocation results");
}}
}}
}},
Err(err) => {{
if let Some(rx) = rx {{
rx.abort();
}}
{tracing}::warn!(?err, "failed to serve `{instance}.{wit_name}` invocation");
{tracing}::warn!(?err, instance = "{instance}", func = "{wit_name}", "failed to serve invocation");
}}
}}
}},
Some(Err(err)) => {{
{tracing}::error!("failed to accept invocation");
{tracing}::error!(?err, instance = "{instance}", func = "{wit_name}", "failed to accept invocation");
}},
None => {{
{tracing}::warn!(instance = "{instance}", func = "{wit_name}", "invocation stream unexpectedly finished");
{anyhow}::bail!("`{instance}.{wit_name}` stream unexpectedly finished")
}},
}}
Expand Down
2 changes: 1 addition & 1 deletion crates/wit-bindgen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wit-bindgen-wrpc"
version = "0.4.1"
version = "0.4.2"
description = """
Rust bindings generator for wRPC.
"""
Expand Down

0 comments on commit 0f97412

Please sign in to comment.