Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Debug formatting for eyre errors when returning to C++ #450

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading