Skip to content

Commit 2c789c1

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

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

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
}}

0 commit comments

Comments
 (0)