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

Adding sdf::Error logging to Param #939

Merged
merged 2 commits into from
May 5, 2022
Merged

Conversation

marcoag
Copy link
Member

@marcoag marcoag commented Apr 6, 2022

🎉 New feature

Work towards #820.

Summary

Adding sdf::Errors &_errors as an argument option to any function that does any logging. The user can now choose to call functions with the sdf::Errors argument to retrieve the error messages or call them without it and get the same old behavior.

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • 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.

@github-actions github-actions bot added the 🌱 garden Ignition Garden label Apr 6, 2022
@codecov-commenter
Copy link

codecov-commenter commented Apr 6, 2022

Codecov Report

Merging #939 (19035ae) into main (ef3a55f) will not change coverage.
The diff coverage is n/a.

❗ Current head 19035ae differs from pull request most recent head 95077d8. Consider uploading reports for the commit 95077d8 to get more accurate results

@@           Coverage Diff           @@
##             main     #939   +/-   ##
=======================================
  Coverage   66.66%   66.66%           
=======================================
  Files           2        2           
  Lines          27       27           
=======================================
  Hits           18       18           
  Misses          9        9           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ef3a55f...95077d8. Read the comment docs.

@chapulina chapulina added mujoco and removed mujoco labels Apr 6, 2022
@@ -147,6 +147,9 @@ namespace sdf
/// \brief Merge include is unspported for the type of entity being
/// included, or the custom parser does not support merge includes.
MERGE_INCLUDE_UNSUPPORTED,

/// \brief Generic error type for parameters.
PARAMETER_ERROR
Copy link
Member

Choose a reason for hiding this comment

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

nit: use a trailing comma

include/sdf/Param.hh Show resolved Hide resolved
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.

I have some minor comments below, but looks great in general! I think it would be good to add tests to ensure that console messages are not accidentally being printed. You can use sdf::testing::RedirectConsoleStream to capture the console output.

include/sdf/Error.hh Outdated Show resolved Hide resolved
include/sdf/Param.hh Show resolved Hide resolved
include/sdf/Param.hh Show resolved Hide resolved
include/sdf/Param.hh Outdated Show resolved Hide resolved
include/sdf/Param.hh Outdated Show resolved Hide resolved
include/sdf/Param.hh Outdated Show resolved Hide resolved
include/sdf/Param.hh Outdated Show resolved Hide resolved
src/Param.cc Outdated Show resolved Hide resolved
src/Param.cc Outdated Show resolved Hide resolved
src/Param.cc Outdated Show resolved Hide resolved
sdferr << errors[i].Message() + "\n";
}

SDF_ASSERT(false, errors.back().Message());
Copy link
Member

Choose a reason for hiding this comment

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

what is the purpose of this assert?

Copy link
Member Author

Choose a reason for hiding this comment

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

The idea was to keep the same behavior as before (see https://github.com/ignitionrobotics/sdformat/blob/e363110e9c5a3671acb371537a6eaef5617f1d28/src/Param.cc#L106 ). Basically, f there are any errors in the vector use the assert to throw the exception with the last added message as it was done previously.

Copy link
Member

Choose a reason for hiding this comment

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

thanks, I hadn't followed the changes closely enough, but I get it now!

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.

I believe the only thing left is to add some tests to ensure error messages are not sent to the console.

include/sdf/Param.hh Outdated Show resolved Hide resolved
src/Param.cc Outdated Show resolved Hide resolved
@@ -0,0 +1,150 @@
/*
* Copyright 2015 Open Source Robotics Foundation
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: 2022

sdf::Error error;
EXPECT_NO_THROW(sdf::Param param1("key", "not_valid_type", "true", false,
errors, "description"));
error = errors.front();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I recommend adding ASSERT_* calls to check errors contains the number of expected errors. Otherwise, we might get a segfault when accessing the items.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, changed EXPECTs to ASSERT.

"description");
error = errors.front();
errors.erase(errors.begin());
ASSERT_EQ(sdf::ErrorCode::PARAMETER_ERROR, error.Code());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be clearer to index into the errors object than to pop each error and assign to error. Here's an example: https://github.com/ignitionrobotics/sdformat/blob/4fa1be3140b827eaf9a954a5800df04442b23ef9/test/integration/frame.cc#L743-L762

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, changed to this format.

@marcoag marcoag force-pushed the marcoag/errorlogging_param branch 3 times, most recently from 662bca5 to 95077d8 Compare May 4, 2022 14:01
azeey added a commit that referenced this pull request May 4, 2022
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
azeey added a commit that referenced this pull request May 4, 2022
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
sdf::Errors errors;
ASSERT_NO_THROW(sdf::Param param1("key", "not_valid_type", "true", false,
errors, "description"));
ASSERT_EQ(errors[0].Code(), sdf::ErrorCode::UNKNOWN_PARAMETER_TYPE);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, I only meant to use ASSERT to check the size of the errors object. Here is my suggestion #1010

@marcoag marcoag force-pushed the marcoag/errorlogging_param branch 2 times, most recently from 5554ec3 to 95077d8 Compare May 5, 2022 04:06
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
@marcoag marcoag force-pushed the marcoag/errorlogging_param branch from 95077d8 to 4ea168c Compare May 5, 2022 12:55
marcoag pushed a commit that referenced this pull request May 5, 2022
@marcoag marcoag force-pushed the marcoag/errorlogging_param branch from ce16a34 to 4ea168c Compare May 5, 2022 14:48
azeey added a commit that referenced this pull request May 5, 2022
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
@azeey azeey merged commit 3099570 into main May 5, 2022
@azeey azeey deleted the marcoag/errorlogging_param branch May 5, 2022 21:09
@ahcorde ahcorde 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
🌱 garden Ignition Garden
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants