-
Notifications
You must be signed in to change notification settings - Fork 100
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
Conversation
Codecov Report
@@ 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.
|
include/sdf/Error.hh
Outdated
@@ -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 |
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: use a trailing comma
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 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.
sdferr << errors[i].Message() + "\n"; | ||
} | ||
|
||
SDF_ASSERT(false, errors.back().Message()); |
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.
what is the purpose of this assert?
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.
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.
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.
thanks, I hadn't followed the changes closely enough, but I get it now!
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 believe the only thing left is to add some tests to ensure error messages are not sent to the console.
test/integration/error_output.cc
Outdated
@@ -0,0 +1,150 @@ | |||
/* | |||
* Copyright 2015 Open Source Robotics Foundation |
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: 2022
test/integration/error_output.cc
Outdated
sdf::Error error; | ||
EXPECT_NO_THROW(sdf::Param param1("key", "not_valid_type", "true", false, | ||
errors, "description")); | ||
error = errors.front(); |
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 recommend adding ASSERT_*
calls to check errors
contains the number of expected errors. Otherwise, we might get a segfault when accessing the items.
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.
Sure, changed EXPECT
s to ASSERT
.
test/integration/error_output.cc
Outdated
"description"); | ||
error = errors.front(); | ||
errors.erase(errors.begin()); | ||
ASSERT_EQ(sdf::ErrorCode::PARAMETER_ERROR, error.Code()); |
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 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
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.
Sure, changed to this format.
662bca5
to
95077d8
Compare
Signed-off-by: Addisu Z. Taddese <[email protected]>
Signed-off-by: Addisu Z. Taddese <[email protected]>
test/integration/error_output.cc
Outdated
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); |
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.
Sorry, I only meant to use ASSERT
to check the size of the errors
object. Here is my suggestion #1010
5554ec3
to
95077d8
Compare
Signed-off-by: Marco A. Gutierrez <[email protected]>
95077d8
to
4ea168c
Compare
…gestions Suggestions for #939
ce16a34
to
4ea168c
Compare
Signed-off-by: Addisu Z. Taddese <[email protected]>
Signed-off-by: Addisu Z. Taddese <[email protected]>
🎉 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 thesdf::Errors
argument to retrieve the error messages or call them without it and get the same old behavior.Checklist
codecheck
passed (See contributing)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.