Skip to content

Commit 67bae86

Browse files
Remove all exit(-1) crash conditions (#3846)
* Update transform_available_condition.cpp * wrapping all examples of get_plugin_type_param in exceptions and making that throw instead of crash * some linting * fix typo * Update controller.cpp * Update nav2_params.yaml * Update nav2_params.yaml
1 parent 7274811 commit 67bae86

File tree

13 files changed

+39
-31
lines changed

13 files changed

+39
-31
lines changed

nav2_behavior_tree/plugins/condition/transform_available_condition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ TransformAvailableCondition::TransformAvailableCondition(
3939
RCLCPP_FATAL(
4040
node_->get_logger(), "Child frame (%s) or parent frame (%s) were empty.",
4141
child_frame_.c_str(), parent_frame_.c_str());
42-
exit(-1);
42+
throw std::runtime_error("TransformAvailableCondition: Child or parent frames not provided!");
4343
}
4444

4545
RCLCPP_DEBUG(node_->get_logger(), "Initialized an TransformAvailableCondition BT node");

nav2_behaviors/src/behavior_server.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ BehaviorServer::loadBehaviorPlugins()
105105
auto node = shared_from_this();
106106

107107
for (size_t i = 0; i != behavior_ids_.size(); i++) {
108-
behavior_types_[i] = nav2_util::get_plugin_type_param(node, behavior_ids_[i]);
109108
try {
109+
behavior_types_[i] = nav2_util::get_plugin_type_param(node, behavior_ids_[i]);
110110
RCLCPP_INFO(
111111
get_logger(), "Creating behavior plugin %s of type %s",
112112
behavior_ids_[i].c_str(), behavior_types_[i].c_str());
113113
behaviors_.push_back(plugin_loader_.createUniqueInstance(behavior_types_[i]));
114-
} catch (const pluginlib::PluginlibException & ex) {
114+
} catch (const std::exception & ex) {
115115
RCLCPP_FATAL(
116116
get_logger(), "Failed to create behavior %s of type %s."
117117
" Exception: %s", behavior_ids_[i].c_str(), behavior_types_[i].c_str(),

nav2_bt_navigator/src/bt_navigator.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ BtNavigator::on_configure(const rclcpp_lifecycle::State & /*state*/)
161161

162162
// Load navigator plugins
163163
for (size_t i = 0; i != navigator_ids.size(); i++) {
164-
std::string navigator_type = nav2_util::get_plugin_type_param(node, navigator_ids[i]);
165164
try {
165+
std::string navigator_type = nav2_util::get_plugin_type_param(node, navigator_ids[i]);
166166
RCLCPP_INFO(
167167
get_logger(), "Creating navigator id %s of type %s",
168168
navigator_ids[i].c_str(), navigator_type.c_str());
@@ -173,11 +173,10 @@ BtNavigator::on_configure(const rclcpp_lifecycle::State & /*state*/)
173173
{
174174
return nav2_util::CallbackReturn::FAILURE;
175175
}
176-
} catch (const pluginlib::PluginlibException & ex) {
176+
} catch (const std::exception & ex) {
177177
RCLCPP_FATAL(
178-
get_logger(), "Failed to create navigator id %s of type %s."
179-
" Exception: %s", navigator_ids[i].c_str(), navigator_type.c_str(),
180-
ex.what());
178+
get_logger(), "Failed to create navigator id %s."
179+
" Exception: %s", navigator_ids[i].c_str(), ex.what());
181180
return nav2_util::CallbackReturn::FAILURE;
182181
}
183182
}

nav2_collision_monitor/src/collision_detector_node.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ bool CollisionDetector::configurePolygons(
224224
polygon_name.c_str());
225225
return false;
226226
}
227-
228227
}
229228
} catch (const std::exception & ex) {
230229
RCLCPP_ERROR(get_logger(), "Error while getting parameters: %s", ex.what());

nav2_controller/src/controller_server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ ControllerServer::on_configure(const rclcpp_lifecycle::State & /*state*/)
142142
progress_checker_ids_[i].c_str(), progress_checker_types_[i].c_str());
143143
progress_checker->initialize(node, progress_checker_ids_[i]);
144144
progress_checkers_.insert({progress_checker_ids_[i], progress_checker});
145-
} catch (const pluginlib::PluginlibException & ex) {
145+
} catch (const std::exception & ex) {
146146
RCLCPP_FATAL(
147147
get_logger(),
148148
"Failed to create progress_checker. Exception: %s", ex.what());

nav2_costmap_2d/include/nav2_costmap_2d/cost_values.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,5 @@ static constexpr unsigned char LETHAL_OBSTACLE = 254;
7272
static constexpr unsigned char INSCRIBED_INFLATED_OBSTACLE = 253;
7373
static constexpr unsigned char MAX_NON_OBSTACLE = 252;
7474
static constexpr unsigned char FREE_SPACE = 0;
75-
}
75+
} // namespace nav2_costmap_2d
7676
#endif // NAV2_COSTMAP_2D__COST_VALUES_HPP_

nav2_costmap_2d/include/nav2_costmap_2d/denoise/image_processing.hpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <array>
2222
#include <memory>
2323
#include <limits>
24+
#include <string>
25+
#include <utility>
2426

2527
namespace nav2_costmap_2d
2628
{
@@ -77,7 +79,7 @@ void morphologyOperation(
7779
const Image<uint8_t> & input, Image<uint8_t> & output,
7880
const Image<uint8_t> & shape, AggregateFn aggregate);
7981

80-
using ShapeBuffer3x3 = std::array<uint8_t, 9>;
82+
using ShapeBuffer3x3 = std::array<uint8_t, 9>; // NOLINT
8183
inline Image<uint8_t> createShape(ShapeBuffer3x3 & buffer, ConnectivityType connectivity);
8284
} // namespace imgproc_impl
8385

@@ -95,7 +97,7 @@ inline void dilate(
9597
const Image<uint8_t> & input, Image<uint8_t> & output,
9698
ConnectivityType connectivity, Max && max_function)
9799
{
98-
using namespace imgproc_impl;
100+
using namespace imgproc_impl; // NOLINT
99101
ShapeBuffer3x3 shape_buffer;
100102
Image<uint8_t> shape = createShape(shape_buffer, connectivity);
101103
morphologyOperation(input, output, shape, max_function);
@@ -376,7 +378,7 @@ struct EquivalenceLabelTreesBase
376378

377379
struct LabelOverflow : public std::runtime_error
378380
{
379-
LabelOverflow(const std::string & message)
381+
explicit LabelOverflow(const std::string & message)
380382
: std::runtime_error(message) {}
381383
};
382384

@@ -464,7 +466,6 @@ class EquivalenceLabelTrees : public EquivalenceLabelTreesBase
464466
{
465467
Label k = 1;
466468
for (Label i = 1; i < next_free_; ++i) {
467-
468469
if (labels_[i] < i) {
469470
labels_[i] = labels_[labels_[i]];
470471
} else {
@@ -504,7 +505,7 @@ class EquivalenceLabelTrees : public EquivalenceLabelTreesBase
504505
* '~' - row continuation in the same style */
505506
max_labels = (rows * columns) / 3 + 1;
506507
}
507-
++max_labels; // add zero label
508+
++max_labels; // add zero label
508509
max_labels = std::min(max_labels, size_t(std::numeric_limits<Label>::max()));
509510
return max_labels;
510511
}
@@ -568,7 +569,7 @@ struct ProcessPixel<ConnectivityType::Way8>
568569
{
569570
Label & current = label.e();
570571

571-
//The decision tree traversal. See reference article for details
572+
// The decision tree traversal. See reference article for details
572573
if (!is_bg(image.e())) {
573574
if (label.b()) {
574575
current = label.b();
@@ -760,17 +761,20 @@ void morphologyOperation(
760761
};
761762

762763
// Apply the central shape row.
763-
// This operation is applicable to all rows of the image, because at any position of the sliding window,
764+
// This operation is applicable to all rows of the image,
765+
// because at any position of the sliding window,
764766
// its central row is located on the image. So we start from the zero line of input and output
765767
probeRows(input, 0, output, 0, shape.row(1), set);
766768

767769
if (input.rows() > 1) {
768770
// Apply the top shape row.
769771
// In the uppermost position of the sliding window, its first row is outside the image border.
770-
// Therefore, we start filling the output image starting from the line 1 and will process input.rows() - 1 lines in total
772+
// Therefore, we start filling the output image starting from the line 1 and will process
773+
// input.rows() - 1 lines in total
771774
probeRows(input, 0, output, 1, shape.row(0), update);
772775
// Apply the bottom shape row.
773-
// Similarly, the input image starting from the line 1 and will process input.rows() - 1 lines in total
776+
// Similarly, the input image starting from the line 1 and will process
777+
// input.rows() - 1 lines in total
774778
probeRows(input, 1, output, 0, shape.row(2), update);
775779
}
776780
}
@@ -812,8 +816,8 @@ Label connectedComponentsImpl(
812816
const Image<uint8_t> & image, Image<Label> & labels,
813817
imgproc_impl::EquivalenceLabelTrees<Label> & label_trees, const IsBg & is_background)
814818
{
815-
using namespace imgproc_impl;
816-
using PixelPass = ProcessPixel<connectivity>;
819+
using namespace imgproc_impl; // NOLINT
820+
using PixelPass = ProcessPixel<connectivity>; // NOLINT
817821

818822
// scanning phase
819823
// scan row 0
@@ -1036,7 +1040,7 @@ Image<Label> connectedComponents(
10361040
const IsBg & is_background,
10371041
Label & total_labels)
10381042
{
1039-
using namespace imgproc_impl;
1043+
using namespace imgproc_impl; // NOLINT
10401044
const size_t pixels = image.rows() * image.columns();
10411045

10421046
if (pixels == 0) {

nav2_costmap_2d/src/costmap_2d_ros.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,13 @@ nav2_util::CallbackReturn
144144
Costmap2DROS::on_configure(const rclcpp_lifecycle::State & /*state*/)
145145
{
146146
RCLCPP_INFO(get_logger(), "Configuring");
147-
getParameters();
147+
try {
148+
getParameters();
149+
} catch (const std::exception & e) {
150+
RCLCPP_ERROR(
151+
get_logger(), "Failed to configure costmap! %s.", e.what());
152+
return nav2_util::CallbackReturn::FAILURE;
153+
}
148154

149155
callback_group_ = create_callback_group(
150156
rclcpp::CallbackGroupType::MutuallyExclusive, false);

nav2_planner/src/planner_server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ PlannerServer::on_configure(const rclcpp_lifecycle::State & /*state*/)
110110
planner_ids_[i].c_str(), planner_types_[i].c_str());
111111
planner->configure(node, planner_ids_[i], tf_, costmap_ros_);
112112
planners_.insert({planner_ids_[i], planner});
113-
} catch (const pluginlib::PluginlibException & ex) {
113+
} catch (const std::exception & ex) {
114114
RCLCPP_FATAL(
115115
get_logger(), "Failed to create global planner. Exception: %s",
116116
ex.what());

nav2_smoother/src/nav2_smoother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ bool SmootherServer::loadSmootherPlugins()
142142
node, smoother_ids_[i], tf_, costmap_sub_,
143143
footprint_sub_);
144144
smoothers_.insert({smoother_ids_[i], smoother});
145-
} catch (const pluginlib::PluginlibException & ex) {
145+
} catch (const std::exception & ex) {
146146
RCLCPP_FATAL(
147147
get_logger(), "Failed to create smoother. Exception: %s",
148148
ex.what());

0 commit comments

Comments
 (0)