fix error handling in material parsing - #122
Conversation
|
@clalancette I just noticed that you also worked on more restrictive material parsing in #104. |
beb1e4e to
9ebb53a
Compare
|
Ping |
9ebb53a to
e787fc8
Compare
|
@scpeters, @clalancette, @sloretz |
e787fc8 to
c5eaa16
Compare
There are 2 main things done here:
1. Check the return value from parseMaterial, parseLink, and
parseJoint. While these can throw a ParseError exception,
most often they return false when they fail to parse.
2. Revamp the error checking around those calls so that the
code is indented a lot less. It is much easier to read this way.
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
Just make the code flow easier to understand. Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
We should consider the return value of parseMaterial(). Redefining the same material again, should be accepted. This often occurs when composing URDFs via xacro. Signed-off-by: Robert Haschke <rhaschke@techfak.uni-bielefeld.de>
c5eaa16 to
44bfb21
Compare
|
I rebased this PR onto rolling. I hope it can be merged after 7 years ;-) |
| catch (ParseError &/*e*/) { | ||
| success = parseMaterial(*material, material_xml, false); // material needs to be fully defined here | ||
| } catch(ParseError & /*e*/) { | ||
| CONSOLE_BRIDGE_logError("material xml is not initialized correctly"); |
There was a problem hiding this comment.
| CONSOLE_BRIDGE_logError("material xml is not initialized correctly"); | |
| CONSOLE_BRIDGE_logError("Exception: material xml is not initialized correctly"); |
There was a problem hiding this comment.
I didn't change the original error message for consistency. If you want to change it anyway, I suggest a more useful message:
| CONSOLE_BRIDGE_logError("material xml is not initialized correctly"); | |
| CONSOLE_BRIDGE_logError("Error parsing material specification."); |
The information that the error is originating from an exception (rather than the return value) is not relevant to a user, I think.
| std::ostream &operator<<(std::ostream &os, const urdf::Rotation& rot) | ||
| { | ||
| double roll, pitch, yaw; | ||
| double x, y, z, w; | ||
| rot.getRPY(roll, pitch, yaw); | ||
| rot.getQuaternion(x, y, z, w); | ||
| os << std::setprecision(9) | ||
| << "x: " << x << " y: " << y << " z: " << z << " w: " << w | ||
| << " roll: " << roll << " pitch: " << pitch << " yaw: "<< yaw; | ||
| return os; | ||
| } |
There was a problem hiding this comment.
Any reason to remove this?
There was a problem hiding this comment.
This was part of @clalancette's cleanup branch, which I built upon. The commit message and motivation was: "quiet down the tests" 😉
| if (!ok) { | ||
| std::cout << "initial rpy: " << r << " " << p << " " << y << "\n" | ||
| << "before " << rot0 << "\n" | ||
| << "after " << rot1 << "\n" | ||
| << "ok " << ok << "\n"; | ||
| } |
| catch (ParseError &/*e*/) { | ||
|
|
||
| if (!success) { | ||
| CONSOLE_BRIDGE_logError("link xml is not initialized correctly"); |
There was a problem hiding this comment.
| CONSOLE_BRIDGE_logError("link xml is not initialized correctly"); | |
| CONSOLE_BRIDGE_logError("link : '%s' xml is not initialized correctly", link->name.c_str()); |
There was a problem hiding this comment.
link is probably not well-defined here. Thus accessing its name will cause a segfault.
We should consider the return value of parseMaterial() to react to plain parsing errors.
Redefining the same material again should be accepted though. This often occurs when composing URDFs via xacro.