Skip to content

Commit 4d414e5

Browse files
committed
chore(rs-bindgen): improve serve logging and error handling
Signed-off-by: Roman Volosatovs <[email protected]>
1 parent d7fcdf1 commit 4d414e5

File tree

6 files changed

+21
-14
lines changed

6 files changed

+21
-14
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ wasmtime = { version = "22", default-features = false }
127127
wasmtime-wasi = { version = "22", default-features = false }
128128
wit-bindgen = { version = "0.27", default-features = false }
129129
wit-bindgen-core = { version = "0.27", default-features = false }
130-
wit-bindgen-wrpc = { version = "0.4.1", default-features = false, path = "./crates/wit-bindgen" }
130+
wit-bindgen-wrpc = { version = "0.4.2", default-features = false, path = "./crates/wit-bindgen" }
131131
wit-bindgen-wrpc-go = { version = "0.2", default-features = false, path = "./crates/wit-bindgen-go" }
132-
wit-bindgen-wrpc-rust = { version = "0.4.1", default-features = false, path = "./crates/wit-bindgen-rust" }
133-
wit-bindgen-wrpc-rust-macro = { version = "0.4", default-features = false, path = "./crates/wit-bindgen-rust-macro" }
132+
wit-bindgen-wrpc-rust = { version = "0.4.2", default-features = false, path = "./crates/wit-bindgen-rust" }
133+
wit-bindgen-wrpc-rust-macro = { version = "0.4.2", default-features = false, path = "./crates/wit-bindgen-rust-macro" }
134134
wit-component = { version = "0.212", default-features = false }
135135
wit-parser = { version = "0.212", default-features = false }
136136
wrpc-cli = { version = "0.2", path = "./crates/cli", default-features = false }

crates/wit-bindgen-rust-macro/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "wit-bindgen-wrpc-rust-macro"
3-
version = "0.4.0"
3+
version = "0.4.2"
44
description = """
55
Procedural macro paired with the `wit-bindgen-wrpc` crate.
66
"""

crates/wit-bindgen-rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "wit-bindgen-wrpc-rust"
3-
version = "0.4.1"
3+
version = "0.4.2"
44
description = """
55
Rust bindings generator for wRPC, typically used through
66
the `wit-bindgen-wrpc` crate's `generate!` macro.

crates/wit-bindgen-rust/src/interface.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,11 @@ pub async fn serve_interface<T: {wrpc_transport}::Serve, U>(
326326
self.src,
327327
r#"
328328
let rx = rx.map({tracing}::Instrument::in_current_span).map({tokio}::spawn);
329+
{tracing}::trace!(instance = "{instance}", func = "{wit_name}", "calling handler");
329330
match {trait_name}::{name}(&handler, cx"#,
330331
tokio = self.gen.tokio_path(),
331332
tracing = self.gen.tracing_path(),
333+
wit_name = func.name,
332334
);
333335
for i in 0..func.params.len() {
334336
uwrite!(self.src, ", p{i}");
@@ -352,8 +354,12 @@ pub async fn serve_interface<T: {wrpc_transport}::Serve, U>(
352354
).await {{
353355
Ok(()) => {{
354356
if let Some(rx) = rx {{
355-
if let Err(err) = rx.await? {{
356-
{tracing}::warn!(?err, "failed to receive async `{instance}.{wit_name}` invocation parameters");
357+
{tracing}::trace!(instance = "{instance}", func = "{wit_name}", "receiving async invocation parameters");
358+
if let Err(err) = {anyhow}::Context::context(
359+
rx.await,
360+
"receipt of async `.{wit_name}` invocation parameters failed",
361+
)? {{
362+
{tracing}::warn!(?err, instance = "{instance}", func = "{wit_name}", "failed to receive async invocation parameters");
357363
}}
358364
}}
359365
continue;
@@ -362,22 +368,23 @@ pub async fn serve_interface<T: {wrpc_transport}::Serve, U>(
362368
if let Some(rx) = rx {{
363369
rx.abort();
364370
}}
365-
{tracing}::warn!(?err, "failed to transmit `{instance}.{wit_name}` invocation results");
371+
{tracing}::warn!(?err, instance = "{instance}", func = "{wit_name}", "failed to transmit invocation results");
366372
}}
367373
}}
368374
}},
369375
Err(err) => {{
370376
if let Some(rx) = rx {{
371377
rx.abort();
372378
}}
373-
{tracing}::warn!(?err, "failed to serve `{instance}.{wit_name}` invocation");
379+
{tracing}::warn!(?err, instance = "{instance}", func = "{wit_name}", "failed to serve invocation");
374380
}}
375381
}}
376382
}},
377383
Some(Err(err)) => {{
378-
{tracing}::error!("failed to accept invocation");
384+
{tracing}::error!(?err, instance = "{instance}", func = "{wit_name}", "failed to accept invocation");
379385
}},
380386
None => {{
387+
{tracing}::warn!(instance = "{instance}", func = "{wit_name}", "invocation stream unexpectedly finished");
381388
{anyhow}::bail!("`{instance}.{wit_name}` stream unexpectedly finished")
382389
}},
383390
}}

crates/wit-bindgen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "wit-bindgen-wrpc"
3-
version = "0.4.1"
3+
version = "0.4.2"
44
description = """
55
Rust bindings generator for wRPC.
66
"""

0 commit comments

Comments
 (0)