Skip to content

Commit

Permalink
update throwOrPrintError and fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
  • Loading branch information
Marco A. Gutierrez committed Mar 16, 2023
1 parent dcf6bb4 commit a4fd3be
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions include/sdf/Element.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <utility>
#include <vector>

#include "sdf/Error.hh"
#include "sdf/Param.hh"
#include "sdf/PrintConfig.hh"
#include "sdf/sdf_config.h"
Expand Down Expand Up @@ -1016,7 +1017,7 @@ namespace sdf
std::pair<T, bool> result = this->Get<T>(errors, _key, _defaultValue);
for(auto& error : errors)
{
error.ThrowOrPrintError(sdferr);
internal::throwOrPrintError(sdferr, error);
}
return result;
}
Expand Down Expand Up @@ -1069,7 +1070,7 @@ namespace sdf
bool result = this->Set<T>(errors, _value);
for(auto& error : errors)
{
error.ThrowOrPrintError(sdferr);
internal::throwOrPrintError(sdferr, error);
}
return result;
}
Expand Down
12 changes: 7 additions & 5 deletions test/integration/error_output.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,14 @@ TEST(ErrorOutput, ElementErrorOutput)
ASSERT_EQ(errors.size(), 1u);
EXPECT_NE(std::string::npos, errors[0].Message().find(
"Missing element description for [nonExistentElement]"));

elem->RemoveChild(sdf::ElementPtr(), errors);
ASSERT_EQ(errors.size(), 1u);
EXPECT_NE(std::string::npos, errors[0].Message().find(
"Cannot remove a nullptr child pointer"));
errors.clear();
// Check nothing has been printed
EXPECT_TRUE(buffer.str().empty()) << buffer.str();

ASSERT_THROW(elem->RemoveChild(sdf::ElementPtr(), errors),
sdf::AssertionInternalError);
ASSERT_EQ(errors.size(), 0u);
buffer.str(std::string());

elem->AddAttribute("key", "std::string", "test", true, errors, "");
ASSERT_EQ(errors.size(), 0u);
Expand Down

0 comments on commit a4fd3be

Please sign in to comment.