Skip to content

Commit

Permalink
Merge pull request #450 from dora-rs/improve-cxx-errors
Browse files Browse the repository at this point in the history
Use `Debug` formatting for eyre errors when returning to C++
  • Loading branch information
phil-opp authored Apr 2, 2024
2 parents 7ede5ba + 4ad8bdd commit a787dc1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions libraries/extensions/ros2-bridge/msg-gen/src/types/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ impl Message {
#[allow(non_snake_case)]
fn #publish(&mut self, message: ffi::#struct_raw_name) -> eyre::Result<()> {
use eyre::Context;
self.0.publish(message).context("publish failed")
self.0.publish(message).context("publish failed").map_err(|e| eyre::eyre!("{e:?}"))
}
}

Expand All @@ -370,7 +370,7 @@ impl Message {
let result = event.event.downcast::<rustdds::dds::result::ReadResult<(ffi::#struct_raw_name, crate::ros2_client::MessageInfo)>>()
.map_err(|_| eyre::eyre!("downcast to {} failed", #struct_raw_name_str))?;

let (data, _info) = result.with_context(|| format!("failed to receive {} event", #subscription_name_str))?;
let (data, _info) = result.with_context(|| format!("failed to receive {} event", #subscription_name_str)).map_err(|e| eyre::eyre!("{e:?}"))?;
Ok(data)
},
_ => eyre::bail!("not a {} event", #subscription_name_str),
Expand Down
11 changes: 7 additions & 4 deletions libraries/extensions/ros2-bridge/msg-gen/src/types/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl Service {
&ros2_client::ServiceTypeName::new(#package_name, #self_name_str),
qos.clone().into(),
qos.into(),
)?;
).map_err(|e| eyre::eyre!("{e:?}"))?;
let (response_tx, response_rx) = flume::bounded(1);
let stream = response_rx.into_stream().map(|v: eyre::Result<_>| Box::new(v) as Box<dyn std::any::Any + 'static>);
let id = events.events.merge(Box::pin(stream));
Expand Down Expand Up @@ -185,7 +185,9 @@ impl Service {
use eyre::WrapErr;
use futures::task::SpawnExt as _;

let request_id = futures::executor::block_on(self.client.async_send_request(request.clone())).context("failed to send request")?;
let request_id = futures::executor::block_on(self.client.async_send_request(request.clone()))
.context("failed to send request")
.map_err(|e| eyre::eyre!("{e:?}"))?;
let client = self.client.clone();
let response_tx = self.response_tx.clone();
let send_result = async move {
Expand All @@ -194,7 +196,7 @@ impl Service {
tracing::warn!("failed to send service response");
}
};
self.executor.spawn(send_result).context("failed to spawn response task")?;
self.executor.spawn(send_result).context("failed to spawn response task").map_err(|e| eyre::eyre!("{e:?}"))?;
Ok(())
}

Expand All @@ -214,7 +216,8 @@ impl Service {
let result = event.event.downcast::<eyre::Result<ffi::#res_type_raw>>()
.map_err(|_| eyre::eyre!("downcast to {} failed", #res_type_raw_str))?;

let data = result.with_context(|| format!("failed to receive {} response", #self_name_str))?;
let data = result.with_context(|| format!("failed to receive {} response", #self_name_str))
.map_err(|e| eyre::eyre!("{e:?}"))?;
Ok(data)
},
_ => eyre::bail!("not a {} response event", #self_name_str),
Expand Down

0 comments on commit a787dc1

Please sign in to comment.