Skip to content

Commit 96e80de

Browse files
authored
Merge pull request #1464 from gazebosim/scpeters/merge_14_main
Merge sdf14 ➡️ main
2 parents 2e86f7b + f1c9fca commit 96e80de

File tree

8 files changed

+143
-44
lines changed

8 files changed

+143
-44
lines changed

include/sdf/Error.hh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ namespace sdf
183183
/// \brief The joint axis mimic does not refer to a valid joint in the
184184
/// current scope.
185185
JOINT_AXIS_MIMIC_INVALID,
186+
187+
/// \brief Error at the XML level.
188+
XML_ERROR,
186189
};
187190

188191
class SDFORMAT_VISIBLE Error

src/Converter.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,15 @@ void Converter::ConvertImpl(tinyxml2::XMLElement *_elem,
264264
}
265265
else if (name == "copy")
266266
{
267-
Move(_elem, childElem, true);
267+
Move(_elem, childElem, true, _errors);
268268
}
269269
else if (name == "map")
270270
{
271271
Map(_elem, childElem, _errors);
272272
}
273273
else if (name == "move")
274274
{
275-
Move(_elem, childElem, false);
275+
Move(_elem, childElem, false, _errors);
276276
}
277277
else if (name == "add")
278278
{
@@ -923,7 +923,8 @@ void Converter::Map(tinyxml2::XMLElement *_elem,
923923
/////////////////////////////////////////////////
924924
void Converter::Move(tinyxml2::XMLElement *_elem,
925925
tinyxml2::XMLElement *_moveElem,
926-
const bool _copy)
926+
const bool _copy,
927+
sdf::Errors &_errors)
927928
{
928929
SDF_ASSERT(_elem != NULL, "SDF element is NULL");
929930
SDF_ASSERT(_moveElem != NULL, "Move element is NULL");
@@ -1024,7 +1025,8 @@ void Converter::Move(tinyxml2::XMLElement *_elem,
10241025

10251026
if (toElemStr && !toAttrStr)
10261027
{
1027-
tinyxml2::XMLNode *cloned = DeepClone(moveFrom->GetDocument(), moveFrom);
1028+
tinyxml2::XMLNode *cloned = DeepClone(_errors, moveFrom->GetDocument(),
1029+
moveFrom);
10281030
tinyxml2::XMLElement *moveTo = static_cast<tinyxml2::XMLElement*>(cloned);
10291031

10301032
moveTo->SetValue(toName);

src/Converter.hh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,11 @@ namespace sdf
108108
/// \param[in] _moveElem A 'convert' element that describes the move
109109
/// operation.
110110
/// \param[in] _copy True to copy the element
111+
/// \param[out] _errors Vector of errors.
111112
private: static void Move(tinyxml2::XMLElement *_elem,
112113
tinyxml2::XMLElement *_moveElem,
113-
const bool _copy);
114+
const bool _copy,
115+
sdf::Errors &_errors);
114116

115117
/// \brief Add an element or attribute to an element.
116118
/// \param[in] _elem The element to receive the value.

src/Converter_TEST.cc

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3370,7 +3370,8 @@ TEST(Converter, World_17_to_18)
33703370
ASSERT_TRUE(errors.empty());
33713371

33723372
// Compare converted xml with expected
3373-
std::string convertedXmlStr = ElementToString(xmlDoc.RootElement());
3373+
std::string convertedXmlStr = ElementToString(errors, xmlDoc.RootElement());
3374+
ASSERT_TRUE(errors.empty());
33743375
ASSERT_FALSE(convertedXmlStr.empty());
33753376

33763377
std::string expectedXmlStr = R"(
@@ -3393,7 +3394,9 @@ TEST(Converter, World_17_to_18)
33933394
tinyxml2::XMLDocument expectedXmlDoc;
33943395
expectedXmlDoc.Parse(expectedXmlStr.c_str());
33953396

3396-
EXPECT_EQ(ElementToString(expectedXmlDoc.RootElement()), convertedXmlStr);
3397+
EXPECT_EQ(ElementToString(errors, expectedXmlDoc.RootElement()),
3398+
convertedXmlStr);
3399+
ASSERT_TRUE(errors.empty());
33973400

33983401
// Check some basic elements
33993402
tinyxml2::XMLElement *convertedElem = xmlDoc.FirstChildElement();
@@ -3509,7 +3512,8 @@ TEST(Converter, World_17_to_18)
35093512
ASSERT_TRUE(errors.empty());
35103513

35113514
// Compare converted xml with expected
3512-
convertedXmlStr = ElementToString(xmlDoc.RootElement());
3515+
convertedXmlStr = ElementToString(errors, xmlDoc.RootElement());
3516+
ASSERT_TRUE(errors.empty());
35133517
ASSERT_FALSE(convertedXmlStr.empty());
35143518

35153519
expectedXmlStr = R"(
@@ -3577,7 +3581,9 @@ TEST(Converter, World_17_to_18)
35773581
expectedXmlDoc.Clear();
35783582
expectedXmlDoc.Parse(expectedXmlStr.c_str());
35793583

3580-
EXPECT_EQ(ElementToString(expectedXmlDoc.RootElement()), convertedXmlStr);
3584+
EXPECT_EQ(ElementToString(errors, expectedXmlDoc.RootElement()),
3585+
convertedXmlStr);
3586+
ASSERT_TRUE(errors.empty());
35813587

35823588

35833589
// ------- Another flattened world in 1.7 format
@@ -3616,7 +3622,8 @@ TEST(Converter, World_17_to_18)
36163622
EXPECT_TRUE(buffer.str().empty()) << buffer.str();
36173623

36183624
// Compare converted xml with expected
3619-
convertedXmlStr = ElementToString(xmlDoc.RootElement());
3625+
convertedXmlStr = ElementToString(errors, xmlDoc.RootElement());
3626+
ASSERT_TRUE(errors.empty());
36203627
ASSERT_FALSE(convertedXmlStr.empty());
36213628

36223629
expectedXmlStr = R"(
@@ -3655,7 +3662,9 @@ TEST(Converter, World_17_to_18)
36553662
expectedXmlDoc.Clear();
36563663
expectedXmlDoc.Parse(expectedXmlStr.c_str());
36573664

3658-
EXPECT_EQ(ElementToString(expectedXmlDoc.RootElement()), convertedXmlStr);
3665+
EXPECT_EQ(ElementToString(errors, expectedXmlDoc.RootElement()),
3666+
convertedXmlStr);
3667+
ASSERT_TRUE(errors.empty());
36593668

36603669
// Check some basic elements
36613670
convertedElem = xmlDoc.FirstChildElement();

src/ParamPassing.cc

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void updateParams(const ParserConfig &_config,
5252
_errors.push_back({ErrorCode::ATTRIBUTE_MISSING,
5353
"Element identifier requires an element_id attribute, but the "
5454
"element_id is not set. Skipping element alteration:\n"
55-
+ ElementToString(childElemXml)
55+
+ ElementToString(_errors, childElemXml)
5656
});
5757
continue;
5858
}
@@ -67,7 +67,7 @@ void updateParams(const ParserConfig &_config,
6767
_errors.push_back({ErrorCode::ATTRIBUTE_INVALID,
6868
"Missing name after double colons in element identifier. "
6969
"Skipping element alteration:\n"
70-
+ ElementToString(childElemXml)
70+
+ ElementToString(_errors, childElemXml)
7171
});
7272
continue;
7373
}
@@ -83,7 +83,7 @@ void updateParams(const ParserConfig &_config,
8383
{
8484
_errors.push_back({ErrorCode::ATTRIBUTE_INVALID,
8585
"Action [" + actionStr + "] is not a valid action. Skipping "
86-
"element alteration:\n" + ElementToString(childElemXml)
86+
"element alteration:\n" + ElementToString(_errors, childElemXml)
8787
});
8888
continue;
8989
}
@@ -102,7 +102,7 @@ void updateParams(const ParserConfig &_config,
102102
_errors.push_back({ErrorCode::ATTRIBUTE_MISSING,
103103
"Element to be added is missing a 'name' attribute. "
104104
"Skipping element addition:\n"
105-
+ ElementToString(childElemXml)
105+
+ ElementToString(_errors, childElemXml)
106106
});
107107
continue;
108108
}
@@ -112,7 +112,7 @@ void updateParams(const ParserConfig &_config,
112112
{
113113
_errors.push_back({ErrorCode::ATTRIBUTE_INVALID,
114114
"The 'name' attribute can not be empty. Skipping element addition:\n"
115-
+ ElementToString(childElemXml)
115+
+ ElementToString(_errors, childElemXml)
116116
});
117117
continue;
118118
}
@@ -129,7 +129,7 @@ void updateParams(const ParserConfig &_config,
129129
+ " element_id='" + childElemXml->Attribute("element_id")
130130
+ "'> because element already exists in included model. "
131131
+ "Skipping element addition:\n"
132-
+ ElementToString(childElemXml)
132+
+ ElementToString(_errors, childElemXml)
133133
});
134134
continue;
135135
}
@@ -157,7 +157,8 @@ void updateParams(const ParserConfig &_config,
157157
_errors.push_back({ErrorCode::ELEMENT_MISSING,
158158
"Could not find element <" + std::string(childElemXml->Name())
159159
+ " element_id='" + childElemXml->Attribute("element_id") + "'>. " +
160-
"Skipping element modification:\n" + ElementToString(childElemXml)
160+
"Skipping element modification:\n" +
161+
ElementToString(_errors, childElemXml)
161162
});
162163
continue;
163164
}
@@ -194,7 +195,7 @@ void updateParams(const ParserConfig &_config,
194195
{
195196
_errors.push_back({ErrorCode::ELEMENT_INVALID,
196197
"Unable to convert XML to SDF. Skipping element replacement:\n"
197-
+ ElementToString(childElemXml)
198+
+ ElementToString(_errors, childElemXml)
198199
});
199200
continue;
200201
}
@@ -355,7 +356,7 @@ ElementPtr initElementDescription(const tinyxml2::XMLElement *_xml,
355356
_errors.push_back({ErrorCode::ELEMENT_INVALID,
356357
"Element [" + std::string(_xml->Name()) + "] is not a defined "
357358
"SDF element. Skipping element alteration\n: "
358-
+ ElementToString(_xml)
359+
+ ElementToString(_errors, _xml)
359360
});
360361
return nullptr;
361362
}
@@ -384,7 +385,7 @@ void handleIndividualChildActions(const ParserConfig &_config,
384385
"Missing an action attribute. Skipping child element modification "
385386
"with parent <" + std::string(_childrenXml->Name()) + " element_id='"
386387
+ std::string(_childrenXml->Attribute("element_id")) + "'>:\n"
387-
+ ElementToString(xmlChild)
388+
+ ElementToString(_errors, xmlChild)
388389
});
389390
continue;
390391
}
@@ -397,7 +398,7 @@ void handleIndividualChildActions(const ParserConfig &_config,
397398
"child element modification with parent <"
398399
+ std::string(_childrenXml->Name()) + " element_id='"
399400
+ std::string(_childrenXml->Attribute("element_id")) + "'>:\n"
400-
+ ElementToString(xmlChild)
401+
+ ElementToString(_errors, xmlChild)
401402
});
402403
continue;
403404
}
@@ -411,7 +412,7 @@ void handleIndividualChildActions(const ParserConfig &_config,
411412
"Could not find element. Skipping child element removal "
412413
"with parent <" + std::string(_childrenXml->Name()) + " element_id='"
413414
+ std::string(_childrenXml->Attribute("element_id")) + "'>:\n"
414-
+ ElementToString(xmlChild)
415+
+ ElementToString(_errors, xmlChild)
415416
});
416417
}
417418
else
@@ -430,7 +431,7 @@ void handleIndividualChildActions(const ParserConfig &_config,
430431
"Could not find element. Skipping child element modification "
431432
"with parent <" + std::string(_childrenXml->Name()) + " element_id='"
432433
+ std::string(_childrenXml->Attribute("element_id")) + "'>:\n"
433-
+ ElementToString(xmlChild)
434+
+ ElementToString(_errors, xmlChild)
434435
});
435436
}
436437
else
@@ -455,7 +456,7 @@ void handleIndividualChildActions(const ParserConfig &_config,
455456
"child element modification with parent <"
456457
+ std::string(_childrenXml->Name()) + " element_id='"
457458
+ std::string(_childrenXml->Attribute("element_id")) + "'>:\n"
458-
+ ElementToString(xmlChild)
459+
+ ElementToString(_errors, xmlChild)
459460
});
460461
continue;
461462
}
@@ -468,7 +469,7 @@ void handleIndividualChildActions(const ParserConfig &_config,
468469
"Unable to convert XML to SDF. Skipping child element alteration "
469470
"with parent <" + std::string(_childrenXml->Name()) + " element_id='"
470471
+ std::string(_childrenXml->Attribute("element_id")) + "'>:\n"
471-
+ ElementToString(xmlChild)
472+
+ ElementToString(_errors, xmlChild)
472473
});
473474
continue;
474475
}
@@ -486,7 +487,7 @@ void handleIndividualChildActions(const ParserConfig &_config,
486487
"Could not find element. Skipping child element replacement "
487488
"with parent <" + std::string(_childrenXml->Name()) + " element_id='"
488489
+ std::string(_childrenXml->Attribute("element_id")) + "'>:\n"
489-
+ ElementToString(xmlChild)
490+
+ ElementToString(_errors, xmlChild)
490491
});
491492
continue;
492493
}
@@ -498,7 +499,7 @@ void handleIndividualChildActions(const ParserConfig &_config,
498499
"Replacement element is missing a 'name' attribute. "
499500
"Skipping element replacement <" + std::string(_childrenXml->Name())
500501
+ " element_id='" + std::string(_childrenXml->Attribute("element_id"))
501-
+ "'>:\n" + ElementToString(xmlChild)
502+
+ "'>:\n" + ElementToString(_errors, xmlChild)
502503
});
503504
continue;
504505
}
@@ -525,7 +526,7 @@ void add(const ParserConfig &_config, const std::string &_source,
525526
{
526527
_errors.push_back({ErrorCode::ELEMENT_INVALID,
527528
"Unable to convert XML to SDF. Skipping element addition:\n"
528-
+ ElementToString(_childXml)
529+
+ ElementToString(_errors, _childXml)
529530
});
530531
}
531532
}
@@ -557,7 +558,8 @@ void modifyAttributes(tinyxml2::XMLElement *_xml,
557558
{
558559
_errors.push_back({ErrorCode::ATTRIBUTE_INVALID,
559560
"Attribute [" + attrName + "] is invalid. "
560-
"Skipping attribute modification in:\n" + ElementToString(_xml)
561+
"Skipping attribute modification in:\n" +
562+
ElementToString(_errors, _xml)
561563
});
562564
continue;
563565
}
@@ -582,7 +584,7 @@ void modifyChildren(tinyxml2::XMLElement *_xml,
582584
{
583585
_errors.push_back({ErrorCode::ELEMENT_MISSING,
584586
"Could not find element [" + elemName + "]. "
585-
"Skipping modification for:\n" + ElementToString(_xml)
587+
"Skipping modification for:\n" + ElementToString(_errors, _xml)
586588
});
587589
continue;
588590
}
@@ -599,7 +601,7 @@ void modifyChildren(tinyxml2::XMLElement *_xml,
599601
_errors.push_back({ErrorCode::ELEMENT_INVALID,
600602
"Value [" + std::string(xmlChild->GetText()) + "] for element ["
601603
+ elemName + "] is invalid. Skipping modification for:\n"
602-
+ ElementToString(_xml)
604+
+ ElementToString(_errors, _xml)
603605
});
604606
continue;
605607
}
@@ -620,9 +622,9 @@ void modifyChildren(tinyxml2::XMLElement *_xml,
620622
// sdf has child elements but no children were specified in xml
621623
std::stringstream ss;
622624
ss << "No modifications for element "
623-
<< ElementToString(xmlChild)
625+
<< ElementToString(_errors, xmlChild)
624626
<< " provided, skipping modification for:\n"
625-
<< ElementToString(_xml);
627+
<< ElementToString(_errors, _xml);
626628
Error err(ErrorCode::WARNING, ss.str());
627629
enforceConfigurablePolicyCondition(
628630
_config.WarningsPolicy(), err, _errors);
@@ -650,7 +652,7 @@ void modify(tinyxml2::XMLElement *_xml, const sdf::ParserConfig &_config,
650652
_errors.push_back({ErrorCode::ELEMENT_INVALID,
651653
"Value [" + std::string(_xml->GetText()) + "] for element [" +
652654
std::string(_xml->Name()) + "] is invalid. Skipping modification for:\n"
653-
+ ElementToString(_xml)
655+
+ ElementToString(_errors, _xml)
654656
});
655657
}
656658
}
@@ -688,7 +690,7 @@ void remove(const tinyxml2::XMLElement *_xml, const sdf::ParserConfig &_config,
688690
+ std::string(xmlParent->Name()) + " element_id='"
689691
+ std::string(xmlParent->Attribute("element_id")) + "'> with parent <"
690692
+ std::string(_xml->Name()) + ">:\n"
691-
+ ElementToString(xmlChild)
693+
+ ElementToString(_errors, xmlChild)
692694
});
693695
continue;
694696
}

0 commit comments

Comments
 (0)