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

Converter: add sdf::Errors output to API methods #1123

Merged
merged 8 commits into from
Nov 30, 2022

Conversation

marcoag
Copy link
Member

@marcoag marcoag commented Aug 31, 2022

Signed-off-by: Marco A. Gutierrez marco@openrobotics.org

🎉 New feature

Work towards #820.

Summary

It moves all error reporting in the Converter class to sdf::Errors. It also includes minimal changes to the parser so the Converter changes can compile and work adequately. A full update to add sdf::Errors support to the parser will follow up on a separate PR so this one is not to big.

After this PR is merged the parser might introduce more errors into the sdf::Errors structure than before. In order to reduce the time this behavior is changed it is recommended to wait until the PR that addresses errors on the parser is ready so it can be merged immediately after this one.

There is one warning that is still printed unless the warnings policy is set to sdf::EnforcementPolicy::ERR.

Test it

Using any method of the Converter class should only print warnings and report all errors through sdf::Errors. If the warnings policy is set to sdf::EnforcementPolicy::ERR warnings should be reported also in the sdf::Errors structure.

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

Comment on lines 60 to 61
XmlUtils.cc
Utils.cc)
Copy link
Member

Choose a reason for hiding this comment

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

nit: alphabetize

Suggested change
XmlUtils.cc
Utils.cc)
Utils.cc
XmlUtils.cc)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in 5612619.

src/Converter.hh Outdated
/// \param[in] _toVersion Version number in string format
/// \param[in] _quiet False to be more verbose
/// \param[in] _toVersion Version number in string format.
/// \param[out] _errors Vector of errors.
Copy link
Member

Choose a reason for hiding this comment

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

it feels a little weird to put an output variable in the middle of the argument list. I think I favor either making output variables the first argument (like SemanticPose::Resolve) so that subsequent input parameters could be optional.

Also, we sometimes pass Errors by reference and sometimes return from the function. It feels weird to both return bool and write to an Errors vector though.

@azeey what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

it feels a little weird to put an output variable in the middle of the argument list. I think I favor either making output variables the first argument (like SemanticPose::Resolve) so that subsequent input parameters could be optional.

Sounds good to me, will apply the changes on this PR.

Also, we sometimes pass Errors by reference and sometimes return from the function. It feels weird to both return bool and write to an Errors vector though.

This seems a bit more tricky since not all the time an error is added to the structure false is returned, meaning errors.empty() != return false, so I'm not sure if there would be trivial way of checking this without changing behavior.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just realized, shall we make the ParserConfig also optional?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this is an internal function, I recommend against making ParserConfig optional. Whoever is calling should be passing a config.

@codecov
Copy link

codecov bot commented Sep 14, 2022

Codecov Report

Merging #1123 (fbd4584) into sdf13 (702dc37) will decrease coverage by 0.32%.
The diff coverage is 53.71%.

@@            Coverage Diff             @@
##            sdf13    #1123      +/-   ##
==========================================
- Coverage   87.53%   87.20%   -0.33%     
==========================================
  Files         124      124              
  Lines       16144    16216      +72     
==========================================
+ Hits        14131    14141      +10     
- Misses       2013     2075      +62     
Impacted Files Coverage Δ
src/parser.cc 86.94% <47.36%> (-0.51%) ⬇️
src/Converter.cc 84.38% <55.47%> (-8.81%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@marcoag marcoag changed the base branch from main to sdf13 October 3, 2022 06:12
@marcoag marcoag force-pushed the marcoag/sdf_error_converter branch from cdf6c6e to 7ab807e Compare October 3, 2022 06:18
Marco A. Gutierrez added 4 commits October 3, 2022 08:30
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
@marcoag marcoag force-pushed the marcoag/sdf_error_converter branch from 7ab807e to ecb8fa2 Compare October 3, 2022 08:57
Copy link
Member

@scpeters scpeters left a comment

Choose a reason for hiding this comment

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

I made some suggestions on how the new APIs in parser.hh should be structured. The Converter.hh APIs are not public, so they are not as critical

include/sdf/parser.hh Show resolved Hide resolved
include/sdf/parser.hh Outdated Show resolved Hide resolved
include/sdf/parser.hh Outdated Show resolved Hide resolved
src/Converter.cc Outdated
ss << "Unknown convert element["
<< name
<< "]";
_errors.push_back({ErrorCode::FATAL_ERROR, ss.str()});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if this is a fatal error.

Copy link
Member Author

@marcoag marcoag Oct 13, 2022

Choose a reason for hiding this comment

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

Definitely not, switched to CONVERSION_ERROR in 5f91d45.

include/sdf/parser.hh Outdated Show resolved Hide resolved
/// \param[out] _errors Vector of errors.
/// \return True on success.
SDFORMAT_VISIBLE
bool convertFile(const std::string &_filename, const std::string &_version,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a TODO to deprecate the other overloads?

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean to deprecate all overloads that we are creating for the error reporting right? where would you say we should put this TODO?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good question. We should definitely create a ticket for it, but I'm not sure we'll remember to check, so I suggest putting a TODO in at least one of these files (probably parser.hh since it's more frequently updated/looked at)

Copy link
Member Author

Choose a reason for hiding this comment

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

Added an issue here and the TODO in 5f91d45.

Marco A. Gutierrez added 2 commits October 13, 2022 09:29
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Marco A. Gutierrez and others added 2 commits November 29, 2022 09:04
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
This returns Errors instead of bool and makes the SDFPtr
the first argument.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
@marcoag marcoag merged commit b1a3334 into sdf13 Nov 30, 2022
@marcoag marcoag deleted the marcoag/sdf_error_converter branch November 30, 2022 07:15
@scpeters scpeters mentioned this pull request May 12, 2023
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants