Skip to content

Commit 3589921

Browse files
authored
more bugfixes for roscore compatibility (#6)
* return correct error when querying a missing parameter * fix: when param subscribers return (1, "", 0) instead of (), don't treat that as an error * make topic type mismatch a soft error, allow subscribing to '*' type (fixes rosbag record)
1 parent c5a7c9e commit 3589921

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

src/client_api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl ClientApi {
6262
caller_id: &str,
6363
key: &str,
6464
value: &Value,
65-
) -> anyhow::Result<()> {
65+
) -> anyhow::Result<Value> {
6666
let request = Call::new("paramUpdate", (caller_id, key, value));
6767
let result = self.client.call(request).await;
6868
Ok(result?)

src/core.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,8 @@ impl Handler for RegisterSubscriberHandler {
256256
let topic = resolve(&caller_id, &topic);
257257

258258
if let Some(known_topic_type) = self.data.topics.read().unwrap().get(&topic.clone()) {
259-
if known_topic_type != &topic_type {
260-
let err_msg = format!(
261-
"{} for topic {} does not match {}",
262-
topic_type, topic, known_topic_type
263-
);
264-
return Ok((0, err_msg, "").try_to_value()?);
259+
if known_topic_type != &topic_type && topic_type != "*" {
260+
log::warn!("Topic '{topic}' was initially published as '{known_topic_type}', but subscriber '{caller_id}' wants it as '{topic_type}'.");
265261
}
266262
}
267263

@@ -376,8 +372,7 @@ impl Handler for RegisterPublisherHandler {
376372

377373
if let Some(v) = self.data.topics.read().unwrap().get(&topic.clone()) {
378374
if v != &topic_type {
379-
let err_msg = format!("{} for topic {} does not match {}", topic_type, topic, v);
380-
return Ok((0, err_msg, Vec::<String>::default()).try_to_value()?);
375+
log::warn!("New publisher for topic '{topic}' has type '{topic_type}', but it is already published as '{v}'.");
381376
}
382377
}
383378

@@ -846,15 +841,16 @@ async fn update_client_with_new_param_value(
846841
subscribing_node_id: String,
847842
param_name: String,
848843
new_value: Value,
849-
) -> Result<(), anyhow::Error> {
844+
) -> Result<Value, anyhow::Error> {
850845
let client_api = ClientApi::new(&client_api_url);
851846
let request = client_api.param_update(&updating_node_id, &param_name, &new_value);
852847
let res = request.await;
853848
match res {
854-
Ok(()) => log::debug!(
855-
"Sent new value for param '{}' to node '{}'.",
849+
Ok(ref v) => log::debug!(
850+
"Sent new value for param '{}' to node '{}'. response: {:?}",
856851
param_name,
857-
subscribing_node_id
852+
subscribing_node_id,
853+
&v
858854
),
859855
Err(ref e) => log::debug!(
860856
"Error sending new value for param '{}' to node '{}': {:?}",
@@ -864,7 +860,7 @@ async fn update_client_with_new_param_value(
864860
),
865861
}
866862

867-
res
863+
Ok(res?)
868864
}
869865

870866
/// Handler for setting a ROS parameter.
@@ -934,8 +930,8 @@ impl Handler for SetParamHandler {
934930

935931
while let Some(res) = update_futures.join_next().await {
936932
match res {
937-
Ok(Ok(())) => {
938-
log::debug!("a subscriber has been updated");
933+
Ok(Ok(v)) => {
934+
log::debug!("a subscriber has been updated (res: {:#?})", &v);
939935
}
940936
Ok(Err(err)) => {
941937
log::warn!(
@@ -986,13 +982,13 @@ impl Handler for GetParamHandler {
986982
log::debug!("GetParamHandler {:?} ", params);
987983
type Request = (String, String);
988984
let (caller_id, key) = Request::try_from_params(params)?;
989-
let key = resolve(&caller_id, &key);
985+
let key_full = resolve(&caller_id, &key);
990986
let params = self.data.parameters.read().unwrap();
991-
let key = key.strip_prefix('/').unwrap_or(&key).split('/');
987+
let key_path = key_full.strip_prefix('/').unwrap_or(&key_full).split('/');
992988

993-
Ok(match params.get(key) {
994-
Some(value) => (1, "", value.to_owned()),
995-
None => (0, "", Value::string("".to_owned())),
989+
Ok(match params.get(key_path) {
990+
Some(value) => (1, "".to_owned(), value.to_owned()),
991+
None => (-1, format!("Parameter [{key_full}] is not set"), Value::i4(0)),
996992
}
997993
.try_to_value()?)
998994
}

0 commit comments

Comments
 (0)