Skip to content

Commit 4658653

Browse files
authored
fix(autoware_route_handler): fix bugprone-exception-escape (#9738)
* fix: bugprone-error Signed-off-by: kobayu858 <yutaro.kobayashi@tier4.jp> * fix: add include Signed-off-by: kobayu858 <yutaro.kobayashi@tier4.jp> --------- Signed-off-by: kobayu858 <yutaro.kobayashi@tier4.jp>
1 parent c476676 commit 4658653

File tree

1 file changed

+57
-40
lines changed

1 file changed

+57
-40
lines changed

planning/autoware_route_handler/src/route_handler.cpp

+57-40
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
#include <algorithm>
3838
#include <functional>
39+
#include <iostream>
3940
#include <limits>
4041
#include <memory>
4142
#include <optional>
@@ -1163,32 +1164,40 @@ lanelet::ConstLanelets RouteHandler::getAllLeftSharedLinestringLanelets(
11631164
const bool & invert_opposite) const noexcept
11641165
{
11651166
lanelet::ConstLanelets linestring_shared;
1166-
auto lanelet_at_left = getLeftLanelet(lane);
1167-
auto lanelet_at_left_opposite = getLeftOppositeLanelets(lane);
1168-
while (lanelet_at_left) {
1169-
linestring_shared.push_back(lanelet_at_left.value());
1170-
lanelet_at_left = getLeftLanelet(lanelet_at_left.value());
1171-
if (!lanelet_at_left) {
1172-
break;
1167+
try {
1168+
auto lanelet_at_left = getLeftLanelet(lane);
1169+
auto lanelet_at_left_opposite = getLeftOppositeLanelets(lane);
1170+
while (lanelet_at_left) {
1171+
linestring_shared.push_back(lanelet_at_left.value());
1172+
lanelet_at_left = getLeftLanelet(lanelet_at_left.value());
1173+
if (!lanelet_at_left) {
1174+
break;
1175+
}
1176+
lanelet_at_left_opposite = getLeftOppositeLanelets(lanelet_at_left.value());
11731177
}
1174-
lanelet_at_left_opposite = getLeftOppositeLanelets(lanelet_at_left.value());
1175-
}
11761178

1177-
if (!lanelet_at_left_opposite.empty() && include_opposite) {
1178-
if (invert_opposite) {
1179-
linestring_shared.push_back(lanelet_at_left_opposite.front().invert());
1180-
} else {
1181-
linestring_shared.push_back(lanelet_at_left_opposite.front());
1182-
}
1183-
auto lanelet_at_right = getRightLanelet(lanelet_at_left_opposite.front());
1184-
while (lanelet_at_right) {
1179+
if (!lanelet_at_left_opposite.empty() && include_opposite) {
11851180
if (invert_opposite) {
1186-
linestring_shared.push_back(lanelet_at_right.value().invert());
1181+
linestring_shared.push_back(lanelet_at_left_opposite.front().invert());
11871182
} else {
1188-
linestring_shared.push_back(lanelet_at_right.value());
1183+
linestring_shared.push_back(lanelet_at_left_opposite.front());
1184+
}
1185+
auto lanelet_at_right = getRightLanelet(lanelet_at_left_opposite.front());
1186+
while (lanelet_at_right) {
1187+
if (invert_opposite) {
1188+
linestring_shared.push_back(lanelet_at_right.value().invert());
1189+
} else {
1190+
linestring_shared.push_back(lanelet_at_right.value());
1191+
}
1192+
lanelet_at_right = getRightLanelet(lanelet_at_right.value());
11891193
}
1190-
lanelet_at_right = getRightLanelet(lanelet_at_right.value());
11911194
}
1195+
} catch (const std::exception & e) {
1196+
std::cerr << "Exception in getAllLeftSharedLinestringLanelets: " << e.what() << std::endl;
1197+
return {};
1198+
} catch (...) {
1199+
std::cerr << "Unknown exception in getAllLeftSharedLinestringLanelets" << std::endl;
1200+
return {};
11921201
}
11931202
return linestring_shared;
11941203
}
@@ -1198,32 +1207,40 @@ lanelet::ConstLanelets RouteHandler::getAllRightSharedLinestringLanelets(
11981207
const bool & invert_opposite) const noexcept
11991208
{
12001209
lanelet::ConstLanelets linestring_shared;
1201-
auto lanelet_at_right = getRightLanelet(lane);
1202-
auto lanelet_at_right_opposite = getRightOppositeLanelets(lane);
1203-
while (lanelet_at_right) {
1204-
linestring_shared.push_back(lanelet_at_right.value());
1205-
lanelet_at_right = getRightLanelet(lanelet_at_right.value());
1206-
if (!lanelet_at_right) {
1207-
break;
1210+
try {
1211+
auto lanelet_at_right = getRightLanelet(lane);
1212+
auto lanelet_at_right_opposite = getRightOppositeLanelets(lane);
1213+
while (lanelet_at_right) {
1214+
linestring_shared.push_back(lanelet_at_right.value());
1215+
lanelet_at_right = getRightLanelet(lanelet_at_right.value());
1216+
if (!lanelet_at_right) {
1217+
break;
1218+
}
1219+
lanelet_at_right_opposite = getRightOppositeLanelets(lanelet_at_right.value());
12081220
}
1209-
lanelet_at_right_opposite = getRightOppositeLanelets(lanelet_at_right.value());
1210-
}
12111221

1212-
if (!lanelet_at_right_opposite.empty() && include_opposite) {
1213-
if (invert_opposite) {
1214-
linestring_shared.push_back(lanelet_at_right_opposite.front().invert());
1215-
} else {
1216-
linestring_shared.push_back(lanelet_at_right_opposite.front());
1217-
}
1218-
auto lanelet_at_left = getLeftLanelet(lanelet_at_right_opposite.front());
1219-
while (lanelet_at_left) {
1222+
if (!lanelet_at_right_opposite.empty() && include_opposite) {
12201223
if (invert_opposite) {
1221-
linestring_shared.push_back(lanelet_at_left.value().invert());
1224+
linestring_shared.push_back(lanelet_at_right_opposite.front().invert());
12221225
} else {
1223-
linestring_shared.push_back(lanelet_at_left.value());
1226+
linestring_shared.push_back(lanelet_at_right_opposite.front());
1227+
}
1228+
auto lanelet_at_left = getLeftLanelet(lanelet_at_right_opposite.front());
1229+
while (lanelet_at_left) {
1230+
if (invert_opposite) {
1231+
linestring_shared.push_back(lanelet_at_left.value().invert());
1232+
} else {
1233+
linestring_shared.push_back(lanelet_at_left.value());
1234+
}
1235+
lanelet_at_left = getLeftLanelet(lanelet_at_left.value());
12241236
}
1225-
lanelet_at_left = getLeftLanelet(lanelet_at_left.value());
12261237
}
1238+
} catch (const std::exception & e) {
1239+
std::cerr << "Exception in getAllRightSharedLinestringLanelets: " << e.what() << std::endl;
1240+
return {};
1241+
} catch (...) {
1242+
std::cerr << "Unknown exception in getAllRightSharedLinestringLanelets" << std::endl;
1243+
return {};
12271244
}
12281245
return linestring_shared;
12291246
}

0 commit comments

Comments
 (0)