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 YAML::BadConversion exception to catch undefined and invalid YAML parameters #1251

Open
wants to merge 1 commit into
base: noetic-devel
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions map_server/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,25 +210,25 @@ class MapServer
#endif
try {
doc["resolution"] >> res;
} catch (YAML::InvalidScalar &) {
} catch (YAML::BadConversion &) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know YAML exceptions well - but should we instead be using the parent class of both InvalidScalar and BadConversion - YAML::RepresentationException?

ROS_ERROR("The map does not contain a resolution tag or it is invalid.");
return false;
}
try {
doc["negate"] >> negate;
} catch (YAML::InvalidScalar &) {
} catch (YAML::BadConversion &) {
ROS_ERROR("The map does not contain a negate tag or it is invalid.");
return false;
}
try {
doc["occupied_thresh"] >> occ_th;
} catch (YAML::InvalidScalar &) {
} catch (YAML::BadConversion &) {
ROS_ERROR("The map does not contain an occupied_thresh tag or it is invalid.");
return false;
}
try {
doc["free_thresh"] >> free_th;
} catch (YAML::InvalidScalar &) {
} catch (YAML::BadConversion &) {
ROS_ERROR("The map does not contain a free_thresh tag or it is invalid.");
return false;
}
Expand All @@ -254,7 +254,7 @@ class MapServer
doc["origin"][0] >> origin[0];
doc["origin"][1] >> origin[1];
doc["origin"][2] >> origin[2];
} catch (YAML::InvalidScalar &) {
} catch (YAML::BadConversion &) {
ROS_ERROR("The map does not contain an origin tag or it is invalid.");
return false;
}
Expand All @@ -275,7 +275,7 @@ class MapServer
mapfpath = dir / mapfpath;
mapfname = mapfpath.string();
}
} catch (YAML::InvalidScalar &) {
} catch (YAML::BadConversion &) {
ROS_ERROR("The map does not contain an image tag or it is invalid.");
return false;
}
Expand Down