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

Make throwOrPrintErrors a member of sdf::Error #1220

Merged
merged 3 commits into from
Jan 17, 2023

Conversation

marcoag
Copy link
Member

@marcoag marcoag commented Jan 13, 2023

Signed-off-by: Marco A. Gutierrez [email protected]

🎉 New feature

Related to #1141.

Summary

Because of the request here and as per IM, moving throwOrPrintErrors into Error.cc so now an Error has a method to be thrown or printed and this can be used in current SDFormat header files.

Test it

Throw any Error object using the new method.

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.

Signed-off-by: Marco A. Gutierrez <[email protected]>
@github-actions github-actions bot added the 🌱 garden Ignition Garden label Jan 13, 2023
@codecov
Copy link

codecov bot commented Jan 13, 2023

Codecov Report

Merging #1220 (f6f1715) into sdf13 (863fe57) will increase coverage by 0.00%.
The diff coverage is 83.33%.

@@           Coverage Diff           @@
##            sdf13    #1220   +/-   ##
=======================================
  Coverage   87.20%   87.20%           
=======================================
  Files         124      124           
  Lines       16229    16232    +3     
=======================================
+ Hits        14152    14155    +3     
  Misses       2077     2077           
Impacted Files Coverage Δ
src/Error.cc 98.48% <80.00%> (-1.52%) ⬇️
src/Utils.cc 87.64% <100.00%> (+0.41%) ⬆️

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

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.

quick nit: Since the title of the PR becomes part of the changelog, mind changing the tense to match the rest of the changelog? We commonly use imperative ("Move throwOrPrintErrors...") or past tense ("Moved throwOrPrintErrors...")

@@ -247,6 +247,10 @@ namespace sdf
/// \sa Element::SetXmlPath
public: void SetXmlPath(const std::string &_xmlPath);

/// \brief It will print the error to sdferr or throw it using
/// SDF_ASSERT depending on its ErrorCode.
public: void throwOrPrintError();
Copy link
Collaborator

Choose a reason for hiding this comment

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

If it's a member function, the first letter should be uppercase.

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 f6f1715.

@@ -247,6 +247,10 @@ namespace sdf
/// \sa Element::SetXmlPath
public: void SetXmlPath(const std::string &_xmlPath);

/// \brief It will print the error to sdferr or throw it using
/// SDF_ASSERT depending on its ErrorCode.
public: void throwOrPrintError();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since it's not modifying anything, it should be a const function

Copy link
Member Author

Choose a reason for hiding this comment

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

True, done in 6483e3a.

src/Utils.cc Outdated
@@ -167,18 +167,11 @@ void enforceConfigurablePolicyCondition(
}

/////////////////////////////////////////////////
void throwOrPrintErrors(const sdf::Errors& _errors)
void throwOrPrintErrors(sdf::Errors& _errors)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't have to make this change if the member function is const.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed back in 6483e3a.

src/Error.cc Outdated
@@ -118,6 +120,19 @@ void Error::SetXmlPath(const std::string &_xmlPath)
this->dataPtr->xmlPath = _xmlPath;
}

/////////////////////////////////////////////////
void Error::throwOrPrintError()
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 a good idea for this to take an ostream object as input so it can be used with sdfwarn and others.

Copy link
Member Author

Choose a reason for hiding this comment

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

sdferr and sdfwarn seem to be ConsoleStream shall it take that one as input instead of the ostream?

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 a ConsoleStream for now in 6483e3a. Let me know if we should do something different.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I thought ConsoleStream inherited from ostream, but that's not the case, so what you have is good.

@marcoag marcoag changed the title moving throwOrPrintErrors into Error.cc Move throwOrPrintErrors into Error.cc Jan 16, 2023
@marcoag marcoag changed the title Move throwOrPrintErrors into Error.cc Make throwOrPrintErrors a member of sdf::Error Jan 16, 2023
Signed-off-by: Marco A. Gutierrez <[email protected]>
src/Error.cc Outdated
@@ -118,6 +120,19 @@ void Error::SetXmlPath(const std::string &_xmlPath)
this->dataPtr->xmlPath = _xmlPath;
}

/////////////////////////////////////////////////
void Error::throwOrPrintError()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I thought ConsoleStream inherited from ostream, but that's not the case, so what you have is good.

@marcoag marcoag merged commit de8b30d into sdf13 Jan 17, 2023
@marcoag marcoag deleted the marcoag/move_throwOrPrintError branch January 17, 2023 22:02
azeey added a commit that referenced this pull request Jan 19, 2023
#1220 added sdf::Error::ThrowOrPrintError, but after further thought, I think it would be better if we made it a free function inside the internal namespace as this allows us to remove the function without a deprecation cycle. Since the future goal of libsdformat is to remove exceptions, it is likely that we'd want to remove ThrowOrPrintError in the not too distance future.

Signed-off-by: Addisu Z. Taddese <[email protected]>
mjcarroll pushed a commit that referenced this pull request Feb 9, 2023
mjcarroll pushed a commit that referenced this pull request Feb 9, 2023
#1220 added sdf::Error::ThrowOrPrintError, but after further thought, I think it would be better if we made it a free function inside the internal namespace as this allows us to remove the function without a deprecation cycle. Since the future goal of libsdformat is to remove exceptions, it is likely that we'd want to remove ThrowOrPrintError in the not too distance future.

Signed-off-by: Addisu Z. Taddese <[email protected]>
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.

2 participants