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

Element: update calls to use sdf::Errors output #1141

Merged
merged 15 commits into from
Mar 21, 2023

Conversation

marcoag
Copy link
Member

@marcoag marcoag commented Sep 15, 2022

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

🎉 New feature

Work towards #820.

Summary

This is an update for the class Element making the calls use sdf::Errors whenever possible to avoid unwanted console outputs.

Test it

Using any method of the Element class with the errors parameter should not print any error.

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.

@codecov
Copy link

codecov bot commented Sep 15, 2022

Codecov Report

Merging #1141 (005f288) into sdf13 (1d1f1d5) will decrease coverage by 0.10%.
The diff coverage is 89.81%.

❗ Current head 005f288 differs from pull request most recent head b9fde35. Consider uploading reports for the commit b9fde35 to get more accurate results

@@            Coverage Diff             @@
##            sdf13    #1141      +/-   ##
==========================================
- Coverage   87.51%   87.42%   -0.10%     
==========================================
  Files         126      126              
  Lines       16248    16314      +66     
==========================================
+ Hits        14220    14262      +42     
- Misses       2028     2052      +24     
Impacted Files Coverage Δ
src/Element.cc 96.21% <88.23%> (-1.01%) ⬇️
include/sdf/Element.hh 97.67% <95.23%> (-2.33%) ⬇️
python/src/sdf/pyError.cc 80.82% <100.00%> (+0.54%) ⬆️

... and 2 files with indirect coverage changes

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

Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
@marcoag marcoag changed the base branch from main to sdf13 October 3, 2022 10:33
@marcoag marcoag force-pushed the marcoag/sdf_error_element_update branch from 5b08d02 to 4f30f5d Compare October 3, 2022 10:33
Copy link
Collaborator

@azeey azeey left a comment

Choose a reason for hiding this comment

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

Looks good, but I would like to see tests that cover some of the most frequently used APIs sugh as Element::Get.

include/sdf/Element.hh Outdated Show resolved Hide resolved
include/sdf/Element.hh Outdated Show resolved Hide resolved
include/sdf/Element.hh Outdated Show resolved Hide resolved
include/sdf/Element.hh Outdated Show resolved Hide resolved
include/sdf/Element.hh Outdated Show resolved Hide resolved
include/sdf/Element.hh Outdated Show resolved Hide resolved
include/sdf/Element.hh Outdated Show resolved Hide resolved
include/sdf/Element.hh Outdated Show resolved Hide resolved
src/Element.cc Show resolved Hide resolved
src/Element.cc Outdated Show resolved Hide resolved
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Marco A. Gutierrez added 2 commits January 17, 2023 19:18
@marcoag
Copy link
Member Author

marcoag commented Jan 17, 2023

Added tests for Get and updated the Set existing ones in 4c83cdc.

The rest of functions changed here seem to only fail when the Element is malformed which I find tricky to create without accessing the private attributes of the class. I modified some of the current tests to make sure they don't return errors nor print any. I guess when the switch is done this should be done for all functions.

@azeey
Copy link
Collaborator

azeey commented Jan 20, 2023

The rest of functions changed here seem to only fail when the Element is malformed which I find tricky to create without accessing the private attributes of the class. I modified some of the current tests to make sure they don't return errors nor print any. I guess when the switch is done this should be done for all functions.

Yes, some of the functions are very unlikely to emit an error, but we might be able to induce some errors by providing ill formed description files. I'll try to look into this.

include/sdf/Element.hh Outdated Show resolved Hide resolved
@azeey
Copy link
Collaborator

azeey commented Jan 21, 2023

The rest of functions changed here seem to only fail when the Element is malformed which I find tricky to create without accessing the private attributes of the class. I modified some of the current tests to make sure they don't return errors nor print any. I guess when the switch is done this should be done for all functions.

Yes, some of the functions are very unlikely to emit an error, but we might be able to induce some errors by providing ill formed description files. I'll try to look into this.

@marcoag I've pushed some changes to azeey/test_element_error_propagation. Namely, I added some tests that check the propagation sdf::Errors in some of the overloads added in this PR.

I was unable to find a way to cause CountNamedElements to emit an error, but in the process of attempting to do that, I realized that by removing SDF_ASSERT calls, we've made it possible for users to end up with a segfault instead of an exception. This is because as opposed to throwing an exception when there is a critical problem, we now insert a fatal error into an sdf::Errors object and continue executing the function. We should instead be checking if a fatal error occurred and returning early. So in the mentioned branch, I have also added a convenience function to check if there are fatal errors after calling a function

sdformat/src/Element.cc

Lines 1243 to 1246 in 6af4be6

std::size_t lastErrorIndex = _errors.size();
this->dataPtr->elementDescriptions.push_back(
parent->GetElementDescription(i)->Clone(_errors));
if (hasFatalError(_errors, lastErrorIndex))

Would you be able to look through Element.cc and probably also Param.cc and add similar logic to places where returning early is necessary?

@azeey
Copy link
Collaborator

azeey commented Jan 31, 2023

Per video call, it would be best to revert all the changes we made code that calls SDF_ASSERT so that exceptions don't cause segfaults. If we remove the console printing in sdf::Exception (

this->Print();
), exceptions could be handled by the end user with no errors printed to the console. I think the original goal of #820 was to remove console messages, not eliminating exceptions, but I think we started removing exceptions as well maybe hoping that it would be fairly straightforward. We should still try to remove exceptions from libsdformat, but we should leave that for another time. /cc @scpeters.

@azeey
Copy link
Collaborator

azeey commented Feb 17, 2023

Can you resolve the conflicts?

@marcoag marcoag force-pushed the marcoag/sdf_error_element_update branch 2 times, most recently from a4fd3be to 4daa82c Compare March 16, 2023 11:00
Marco A. Gutierrez added 3 commits March 16, 2023 19:01
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Copy link
Collaborator

@azeey azeey left a comment

Choose a reason for hiding this comment

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

LGTM! Just a few minor comments

src/Element.cc Outdated Show resolved Hide resolved
src/Element.cc Outdated Show resolved Hide resolved
src/Element_TEST.cc Outdated Show resolved Hide resolved
test/integration/error_output.cc Show resolved Hide resolved
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
@marcoag marcoag mentioned this pull request Mar 21, 2023
8 tasks
Copy link
Collaborator

@azeey azeey left a comment

Choose a reason for hiding this comment

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

Thanks for iterating! I'll go ahead and merge!

src/Element_TEST.cc Outdated Show resolved Hide resolved
@azeey azeey enabled auto-merge (squash) March 21, 2023 18:43
@azeey azeey merged commit 131750f into sdf13 Mar 21, 2023
@azeey azeey deleted the marcoag/sdf_error_element_update branch March 21, 2023 19:11
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.

2 participants