Skip to content

Commit d0ab1aa

Browse files
facontidavideclaude
andcommitted
fix: Log exception details in subscribe() and refresh() catch blocks
Previously both methods caught exceptions and returned false with no logging, making failures impossible to diagnose. Now logs the exception message with full context. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: 00acef786069
1 parent 77fc1ae commit d0ab1aa

2 files changed

Lines changed: 6 additions & 26 deletions

File tree

src/generic_subscription_manager.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,6 @@
1717
* along with pj_ros_bridge. If not, see <https://www.gnu.org/licenses/>.
1818
*/
1919

20-
// Licensed under the Apache License, Version 2.0 (the "License");
21-
// you may not use this file except in compliance with the License.
22-
// You may obtain a copy of the License at
23-
//
24-
// http://www.apache.org/licenses/LICENSE-2.0
25-
//
26-
// Unless required by applicable law or agreed to in writing, software
27-
// distributed under the License is distributed on an "AS IS" BASIS,
28-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29-
// See the License for the specific language governing permissions and
30-
// limitations under the License.
31-
3220
#include "pj_ros_bridge/generic_subscription_manager.hpp"
3321

3422
#include "pj_ros_bridge/time_utils.hpp"
@@ -67,7 +55,10 @@ bool GenericSubscriptionManager::subscribe(
6755
subscriptions_[topic_name] = std::move(info);
6856

6957
return true;
70-
} catch (const std::exception&) {
58+
} catch (const std::exception& e) {
59+
RCLCPP_ERROR(
60+
node_->get_logger(), "Failed to create subscription for topic '%s' (type '%s'): %s", topic_name.c_str(),
61+
topic_type.c_str(), e.what());
7162
return false;
7263
}
7364
}

src/topic_discovery.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,6 @@
1717
* along with pj_ros_bridge. If not, see <https://www.gnu.org/licenses/>.
1818
*/
1919

20-
// Licensed under the Apache License, Version 2.0 (the "License");
21-
// you may not use this file except in compliance with the License.
22-
// You may obtain a copy of the License at
23-
//
24-
// http://www.apache.org/licenses/LICENSE-2.0
25-
//
26-
// Unless required by applicable law or agreed to in writing, software
27-
// distributed under the License is distributed on an "AS IS" BASIS,
28-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29-
// See the License for the specific language governing permissions and
30-
// limitations under the License.
31-
3220
#include "pj_ros_bridge/topic_discovery.hpp"
3321

3422
namespace pj_ros_bridge {
@@ -66,7 +54,8 @@ bool TopicDiscovery::refresh() {
6654
try {
6755
discover_topics();
6856
return true;
69-
} catch (const std::exception&) {
57+
} catch (const std::exception& e) {
58+
RCLCPP_ERROR(node_->get_logger(), "Topic discovery refresh failed: %s", e.what());
7059
return false;
7160
}
7261
}

0 commit comments

Comments
 (0)