-
Notifications
You must be signed in to change notification settings - Fork 95
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
Add EnforcementPolicy in ParserConfig to enable configurable parsing strictness #481
Conversation
ae3cf0d
to
166b995
Compare
Force pushed 166b995 with a small amount of cleanup. |
src/parser.cc
Outdated
<< "], child of element[" << _xml->Value() | ||
<< "], not defined in SDF. Copying[" << elemXml->Value() << "] " | ||
<< "as children of [" << _xml->Value() << "].\n"; | ||
|
||
addRecoverableWarning( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, for now this changes the default behavior for this specific check back to warn. However, this function takes in a policy enum value so it could be overridden for the default case with something like:
sdf::WarningsPolicy policy = _config.WarningsPolicy();
if (policy != sdf::WarningsPolicy::PEDANTIC)
policy = sdf::WarningsPolicy::IGNORED;
It might also be desired to separate WarningsPolicy and add something specific like _config.IgnoreUnrecognizedElements()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we've gone back and forth on this behavior in the past, I would vote for having _config.IgnoreUnrecognizedElements()
or something similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yah, the more I think about it that makes sense. I switched this back to warn and I'll open a separate PR for easy review of the new additions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, after working on it I decided to update this PR. I think there is enough overlap between the two policies that they should have a common enum, which necessitated changes here.
src/parser.cc
Outdated
sdfwarn << "Converting a deprecated SDF source[" << _source << "].\n"; | ||
std::stringstream ss; | ||
ss << "Converting a deprecated SDF source[" << _source << "].\n"; | ||
addRecoverableWarning( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we want to emit an error for reading an older SDFormat file even when the policy is PEDANTIC. The version of readDoc
that takes a SDFPtr
uses sdfdbg
for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched to sdfdbg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, with the new commit this should be easy to add a policy for this in the future should it be desired.
@@ -0,0 +1,11 @@ | |||
<?xml version="1.0" ?> | |||
<sdf version="1.6"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change the version to 1.8 and use an xmlns
attribute to make the xml valid?
<sdf version="1.6"> | |
<sdf version="1.8" xmlns:third_party_software="custom_ns_uri"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -0,0 +1,11 @@ | |||
<?xml version="1.0" ?> | |||
<sdf version="1.6"> | |||
<model name="joint_incorrect_tags" some_attribute="staheousth"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: what's staheousth
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some arbitrary text content. Changed to "some value"
src/Utils.hh
Outdated
@@ -21,8 +21,10 @@ | |||
#include <string> | |||
#include <optional> | |||
#include <vector> | |||
#include "sdf/Console.hh" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it was for sdfwarn/sdfdbg, but I guess not. Removed
src/parser.cc
Outdated
<< "], child of element[" << _xml->Value() | ||
<< "], not defined in SDF. Copying[" << elemXml->Value() << "] " | ||
<< "as children of [" << _xml->Value() << "].\n"; | ||
|
||
addRecoverableWarning( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we've gone back and forth on this behavior in the past, I would vote for having _config.IgnoreUnrecognizedElements()
or something similar.
e49b501
to
f667520
Compare
Err, had to remove the added tests since they will be carried over to the next PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After working on a separate commit to handle unrecognized elements, I realized that there was a lot in common with the warnings policy that they should share the same enum, which necessitated some reworking of the naming of different parts.
That said, I think it adds a good framework for adding new recoverable conditions like these in the future.
src/parser.cc
Outdated
<< "], child of element[" << _xml->Value() | ||
<< "], not defined in SDF. Copying[" << elemXml->Value() << "] " | ||
<< "as children of [" << _xml->Value() << "].\n"; | ||
|
||
addRecoverableWarning( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, after working on it I decided to update this PR. I think there is enough overlap between the two policies that they should have a common enum, which necessitated changes here.
src/parser.cc
Outdated
sdfwarn << "Converting a deprecated SDF source[" << _source << "].\n"; | ||
std::stringstream ss; | ||
ss << "Converting a deprecated SDF source[" << _source << "].\n"; | ||
addRecoverableWarning( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, with the new commit this should be easy to add a policy for this in the future should it be desired.
d0915ea
to
9c688dd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a couple of minor comments. Looks great!
test/integration/unknown.cc
Outdated
config.SetUnrecognizedElementsPolicy(sdf::EnforcementPolicy::ERR); | ||
sdf::Root root; | ||
const auto errors = root.Load(testFile, config); | ||
EXPECT_FALSE(errors.empty()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add an expectation on at least one of the output messages? Just so it doesn't pass due to other non-related error messages in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -0,0 +1,11 @@ | |||
<?xml version="1.0" ?> | |||
<sdf version="1.8" xmlns:third_party_software="custom_ns_uri"> | |||
<model name="joint_incorrect_tags" some_attribute="some value"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: joint_incorrect_tags
makes it sound this is is not a valid file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the name to namespaced_tags
Signed-off-by: Stephen Brawner <brawner@gmail.com>
Signed-off-by: Stephen Brawner <brawner@gmail.com>
259b285
to
73a9d98
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is awesome! it shouldn't be in this PR, but I'd love to add a flag to ign sdf
commands for setting the parsing level
|
Thanks for the reviews you two! |
This PR depends on #439, but the PR branch is in a different fork so I can't target it directly.
The added commit is 166b995
This PR adds a configurable WarningsPolicy in ParserConfig to allow users to customize the strictness of the parser. In some cases, a best-effort parse is desired and warnings either streamed to sdfwarn or sdfdbg. But in other cases, like unit tests for example, it makes sense to be pedantic about warnings.
Fixes #473, #327
This is a first approach after discussion over at #473 and I'm totally open to other approaches. Likewise, based on the use cases described in #473 and Bitbucket PR, it might also make sense to add a second configuration option specifically for unrecognized elements.