Skip to content

Commit 30671a5

Browse files
author
Marco A. Gutierrez
committed
moving output params first, removing POINTER_ERROR
Signed-off-by: Marco A. Gutierrez <[email protected]>
1 parent ff1e93e commit 30671a5

File tree

4 files changed

+53
-54
lines changed

4 files changed

+53
-54
lines changed

include/sdf/Error.hh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,6 @@ namespace sdf
179179

180180
/// \brief Generic error during parsing.
181181
PARSING_ERROR,
182-
183-
/// \brief Error trying to access a pointer.
184-
POINTER_ERROR,
185182
};
186183

187184
class SDFORMAT_VISIBLE Error

include/sdf/parser.hh

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -364,14 +364,14 @@ namespace sdf
364364
std::string getModelFilePath(const std::string &_modelDirPath);
365365

366366
/// \brief Get the file path to the model file
367-
/// \param[in] _modelDirPath directory system path of the model
368367
/// \param[out] _errors Vector of errors.
368+
/// \param[in] _modelDirPath directory system path of the model
369369
/// \return string with the full filesystem path to the best version (greater
370370
/// SDF protocol supported by this sdformat version) of the .sdf
371371
/// model files hosted by _modelDirPath.
372372
SDFORMAT_VISIBLE
373-
std::string getModelFilePath(const std::string &_modelDirPath,
374-
sdf::Errors &_errors);
373+
std::string getModelFilePath(sdf::Errors &_errors,
374+
const std::string &_modelDirPath);
375375

376376
/// \brief Convert an SDF file to a specific SDF version.
377377
/// \param[in] _filename Name of the SDF file to convert.
@@ -448,11 +448,11 @@ namespace sdf
448448
/// not empty.
449449
/// This checks recursively and should check the files exhaustively
450450
/// rather than terminating early when the first error is found.
451-
/// \param[in] _root SDF Root object to check recursively.
452451
/// \param[out] _errors Vector of errors.
452+
/// \param[in] _root SDF Root object to check recursively.
453453
/// \return True if all models have valid canonical_link attributes.
454454
SDFORMAT_VISIBLE
455-
bool checkCanonicalLinkNames(const sdf::Root *_root, sdf::Errors &_errors);
455+
bool checkCanonicalLinkNames(sdf::Errors &_errors, const sdf::Root *_root);
456456

457457
/// \brief For the world and each model, check that the attached_to graphs
458458
/// build without errors and have no cycles.
@@ -471,11 +471,11 @@ namespace sdf
471471
/// leads to a model, link, or world frame.
472472
/// This checks recursively and should check the files exhaustively
473473
/// rather than terminating early when the first error is found.
474-
/// \param[in] _root SDF Root object to check recursively.
475474
/// \param[out] _errors Vector of errors.
475+
/// \param[in] _root SDF Root object to check recursively.
476476
/// \return True if all attached_to graphs are valid.
477477
SDFORMAT_VISIBLE
478-
bool checkFrameAttachedToGraph(const sdf::Root *_root, sdf::Errors &_errors);
478+
bool checkFrameAttachedToGraph(sdf::Errors &_errors, const sdf::Root *_root);
479479

480480
/// \brief Check that for each frame, the attached_to attribute value
481481
/// does not match its own frame name but does match the name of a
@@ -494,11 +494,11 @@ namespace sdf
494494
/// not empty.
495495
/// This checks recursively and should check the files exhaustively
496496
/// rather than terminating early when the first error is found.
497-
/// \param[in] _root SDF Root object to check recursively.
498497
/// \param[out] _errors Vector of errors.
498+
/// \param[in] _root SDF Root object to check recursively.
499499
/// \return True if all frames have valid attached_to attributes.
500500
SDFORMAT_VISIBLE
501-
bool checkFrameAttachedToNames(const sdf::Root *_root, sdf::Errors &_errors);
501+
bool checkFrameAttachedToNames(sdf::Errors &_errors, const sdf::Root *_root);
502502

503503
/// \brief Check that all joints in contained models specify parent
504504
/// and child link names that match the names of sibling links.
@@ -557,11 +557,11 @@ namespace sdf
557557
/// leads to a model, link, or world frame.
558558
/// This checks recursively and should check the files exhaustively
559559
/// rather than terminating early when the first error is found.
560-
/// \param[in] _root SDF Root object to check recursively.
561560
/// \param[out] _errors Vector of errors.
561+
/// \param[in] _root SDF Root object to check recursively.
562562
/// \return True if all attached_to graphs are valid.
563563
SDFORMAT_VISIBLE
564-
bool checkPoseRelativeToGraph(const sdf::Root *_root, sdf::Errors &_errors);
564+
bool checkPoseRelativeToGraph( sdf::Errors &_errors, const sdf::Root *_root);
565565

566566
/// \brief Check that all sibling elements of the same type have unique names.
567567
/// This checks recursively and should check the files exhaustively
@@ -575,13 +575,13 @@ namespace sdf
575575
/// \brief Check that all sibling elements of the same type have unique names.
576576
/// This checks recursively and should check the files exhaustively
577577
/// rather than terminating early when the first duplicate name is found.
578-
/// \param[in] _elem SDF Element to check recursively.
579578
/// \param[out] _errors Vector of errors.
579+
/// \param[in] _elem SDF Element to check recursively.
580580
/// \return True if all contained elements have do not share a name with
581581
/// sibling elements of the same type.
582582
SDFORMAT_VISIBLE
583-
bool recursiveSameTypeUniqueNames(sdf::ElementPtr _elem,
584-
sdf::Errors &_errors);
583+
bool recursiveSameTypeUniqueNames(sdf::Errors &_errors,
584+
sdf::ElementPtr _elem);
585585

586586
/// \brief Check that all sibling elements of the any type have unique names.
587587
/// This checks recursively and should check the files exhaustively
@@ -595,12 +595,12 @@ namespace sdf
595595
/// \brief Check that all sibling elements of the any type have unique names.
596596
/// This checks recursively and should check the files exhaustively
597597
/// rather than terminating early when the first duplicate name is found.
598-
/// \param[in] _elem SDF Element to check recursively.
599598
/// \param[out] _errors Vector of errors.
599+
/// \param[in] _elem SDF Element to check recursively.
600600
/// \return True if all contained elements have do not share a name with
601601
/// sibling elements of any type.
602602
SDFORMAT_VISIBLE
603-
bool recursiveSiblingUniqueNames(sdf::ElementPtr _elem, sdf::Errors &_errors);
603+
bool recursiveSiblingUniqueNames(sdf::Errors &_errors, sdf::ElementPtr _elem);
604604

605605
/// \brief Check that all sibling elements do not contain the delimiter
606606
/// double colons '::' in element names, which is reserved for forming scopes
@@ -617,12 +617,12 @@ namespace sdf
617617
/// in SDFormat 1.8. This checks recursively and should check the files
618618
/// exhaustively rather than terminating early when the first name
619619
/// containing '::' is found.
620-
/// \param[in] _elem SDF Element to check recursively.
621620
/// \param[out] _errors Vector of errors.
621+
/// \param[in] _elem SDF Element to check recursively.
622622
/// \return True if all contained element names do not have the delimiter '::'
623623
SDFORMAT_VISIBLE
624-
bool recursiveSiblingNoDoubleColonInNames(sdf::ElementPtr _elem,
625-
sdf::Errors &_errors);
624+
bool recursiveSiblingNoDoubleColonInNames(sdf::Errors &_errors,
625+
sdf::ElementPtr _elem);
626626

627627
/// \brief Check whether the element should be validated. If this returns
628628
/// false, validators such as the unique name and reserve name checkers should

src/parser.cc

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ bool readFileInternal(const std::string &_filename, const bool _convert,
817817

818818
if (filesystem::is_directory(filename))
819819
{
820-
filename = getModelFilePath(filename, _errors);
820+
filename = getModelFilePath(_errors, filename);
821821
}
822822

823823
if (!filesystem::exists(filename))
@@ -1095,7 +1095,7 @@ bool readDoc(tinyxml2::XMLDocument *_xmlDoc, SDFPtr _sdf,
10951095
// delimiter '::' in element names not allowed in SDFormat >= 1.8
10961096
gz::math::SemanticVersion sdfVersion(_sdf->Root()->OriginalVersion());
10971097
if (sdfVersion >= gz::math::SemanticVersion(1, 8)
1098-
&& !recursiveSiblingNoDoubleColonInNames(_sdf->Root(), _errors))
1098+
&& !recursiveSiblingNoDoubleColonInNames(_errors, _sdf->Root()))
10991099
{
11001100
_errors.push_back({ErrorCode::RESERVED_NAME,
11011101
"Delimiter '::' found in attribute names of element <"
@@ -1189,7 +1189,7 @@ bool readDoc(tinyxml2::XMLDocument *_xmlDoc, ElementPtr _sdf,
11891189
// delimiter '::' in element names not allowed in SDFormat >= 1.8
11901190
gz::math::SemanticVersion sdfVersion(_sdf->OriginalVersion());
11911191
if (sdfVersion >= gz::math::SemanticVersion(1, 8)
1192-
&& !recursiveSiblingNoDoubleColonInNames(_sdf, _errors))
1192+
&& !recursiveSiblingNoDoubleColonInNames(_errors, _sdf))
11931193
{
11941194
_errors.push_back({ErrorCode::RESERVED_NAME,
11951195
"Delimiter '::' found in attribute names of element <" +
@@ -1325,14 +1325,14 @@ std::string getBestSupportedModelVersion(tinyxml2::XMLElement *_modelXML,
13251325
std::string getModelFilePath(const std::string &_modelDirPath)
13261326
{
13271327
sdf::Errors errors;
1328-
std::string result = getModelFilePath(_modelDirPath, errors);
1328+
std::string result = getModelFilePath(errors, _modelDirPath);
13291329
sdf::throwOrPrintErrors(errors);
13301330
return result;
13311331
}
13321332

13331333
//////////////////////////////////////////////////
1334-
std::string getModelFilePath(const std::string &_modelDirPath,
1335-
sdf::Errors &_errors)
1334+
std::string getModelFilePath(sdf::Errors &_errors,
1335+
const std::string &_modelDirPath)
13361336
{
13371337
std::string configFilePath;
13381338

@@ -1546,7 +1546,7 @@ static bool resolveFileNameFromUri(tinyxml2::XMLElement *_includeXml,
15461546
if (sdf::filesystem::is_directory(modelPath))
15471547
{
15481548
// Get the model.config filename
1549-
_fileName = getModelFilePath(modelPath);
1549+
_fileName = getModelFilePath(_errors, modelPath);
15501550

15511551
if (_fileName.empty())
15521552
{
@@ -2222,17 +2222,17 @@ sdf::Errors convertString(SDFPtr _sdf, const std::string &_sdfString,
22222222
bool checkCanonicalLinkNames(const sdf::Root *_root)
22232223
{
22242224
sdf::Errors errors;
2225-
bool result = checkCanonicalLinkNames(_root, errors);
2225+
bool result = checkCanonicalLinkNames(errors, _root);
22262226
sdf::throwOrPrintErrors(errors);
22272227
return result;
22282228
}
22292229

22302230
//////////////////////////////////////////////////
2231-
bool checkCanonicalLinkNames(const sdf::Root *_root, sdf::Errors &_errors)
2231+
bool checkCanonicalLinkNames(sdf::Errors &_errors, const sdf::Root *_root)
22322232
{
22332233
if (!_root)
22342234
{
2235-
_errors.push_back({ErrorCode::POINTER_ERROR, "Error: invalid sdf::Root "
2235+
_errors.push_back({ErrorCode::FATAL_ERROR, "Error: invalid sdf::Root "
22362236
"pointer, unable to check canonical link names."});
22372237
return false;
22382238
}
@@ -2277,13 +2277,13 @@ bool checkCanonicalLinkNames(const sdf::Root *_root, sdf::Errors &_errors)
22772277
bool checkFrameAttachedToNames(const sdf::Root *_root)
22782278
{
22792279
sdf::Errors errors;
2280-
bool result = checkFrameAttachedToNames(_root, errors);
2280+
bool result = checkFrameAttachedToNames(errors, _root);
22812281
sdf::throwOrPrintErrors(errors);
22822282
return result;
22832283
}
22842284

22852285
//////////////////////////////////////////////////
2286-
bool checkFrameAttachedToNames(const sdf::Root *_root, sdf::Errors &_errors)
2286+
bool checkFrameAttachedToNames(sdf::Errors &_errors, const sdf::Root *_root)
22872287
{
22882288
bool result = true;
22892289

@@ -2420,13 +2420,13 @@ bool checkFrameAttachedToNames(const sdf::Root *_root, sdf::Errors &_errors)
24202420
bool recursiveSameTypeUniqueNames(sdf::ElementPtr _elem)
24212421
{
24222422
sdf::Errors errors;
2423-
bool result = recursiveSameTypeUniqueNames(_elem, errors);
2423+
bool result = recursiveSameTypeUniqueNames(errors, _elem);
24242424
sdf::throwOrPrintErrors(errors);
24252425
return result;
24262426
}
24272427

24282428
//////////////////////////////////////////////////
2429-
bool recursiveSameTypeUniqueNames(sdf::ElementPtr _elem, sdf::Errors &_errors)
2429+
bool recursiveSameTypeUniqueNames(sdf::Errors &_errors, sdf::ElementPtr _elem)
24302430
{
24312431
if (!shouldValidateElement(_elem))
24322432
return true;
@@ -2447,7 +2447,7 @@ bool recursiveSameTypeUniqueNames(sdf::ElementPtr _elem, sdf::Errors &_errors)
24472447
sdf::ElementPtr child = _elem->GetFirstElement();
24482448
while (child)
24492449
{
2450-
result = recursiveSameTypeUniqueNames(child, _errors) && result;
2450+
result = recursiveSameTypeUniqueNames(_errors, child) && result;
24512451
child = child->GetNextElement();
24522452
}
24532453

@@ -2458,13 +2458,13 @@ bool recursiveSameTypeUniqueNames(sdf::ElementPtr _elem, sdf::Errors &_errors)
24582458
bool recursiveSiblingUniqueNames(sdf::ElementPtr _elem)
24592459
{
24602460
sdf::Errors errors;
2461-
bool result = recursiveSiblingUniqueNames(_elem, errors);
2461+
bool result = recursiveSiblingUniqueNames(errors, _elem);
24622462
sdf::throwOrPrintErrors(errors);
24632463
return result;
24642464
}
24652465

24662466
//////////////////////////////////////////////////
2467-
bool recursiveSiblingUniqueNames(sdf::ElementPtr _elem, sdf::Errors &_errors)
2467+
bool recursiveSiblingUniqueNames(sdf::Errors &_errors, sdf::ElementPtr _elem)
24682468
{
24692469
if (!shouldValidateElement(_elem))
24702470
return true;
@@ -2482,7 +2482,7 @@ bool recursiveSiblingUniqueNames(sdf::ElementPtr _elem, sdf::Errors &_errors)
24822482
sdf::ElementPtr child = _elem->GetFirstElement();
24832483
while (child)
24842484
{
2485-
result = recursiveSiblingUniqueNames(child) && result;
2485+
result = recursiveSiblingUniqueNames(_errors, child) && result;
24862486
child = child->GetNextElement();
24872487
}
24882488

@@ -2493,14 +2493,14 @@ bool recursiveSiblingUniqueNames(sdf::ElementPtr _elem, sdf::Errors &_errors)
24932493
bool recursiveSiblingNoDoubleColonInNames(sdf::ElementPtr _elem)
24942494
{
24952495
sdf::Errors errors;
2496-
bool result = recursiveSiblingNoDoubleColonInNames(_elem, errors);
2496+
bool result = recursiveSiblingNoDoubleColonInNames(errors, _elem);
24972497
sdf::throwOrPrintErrors(errors);
24982498
return result;
24992499
}
25002500

25012501
//////////////////////////////////////////////////
2502-
bool recursiveSiblingNoDoubleColonInNames(sdf::ElementPtr _elem,
2503-
sdf::Errors &_errors)
2502+
bool recursiveSiblingNoDoubleColonInNames(sdf::Errors &_errors,
2503+
sdf::ElementPtr _elem)
25042504
{
25052505
if (!shouldValidateElement(_elem))
25062506
return true;
@@ -2518,7 +2518,7 @@ bool recursiveSiblingNoDoubleColonInNames(sdf::ElementPtr _elem,
25182518
sdf::ElementPtr child = _elem->GetFirstElement();
25192519
while (child)
25202520
{
2521-
result = recursiveSiblingNoDoubleColonInNames(child, _errors) && result;
2521+
result = recursiveSiblingNoDoubleColonInNames(_errors, child) && result;
25222522
child = child->GetNextElement();
25232523
}
25242524

@@ -2529,13 +2529,13 @@ bool recursiveSiblingNoDoubleColonInNames(sdf::ElementPtr _elem,
25292529
bool checkFrameAttachedToGraph(const sdf::Root *_root)
25302530
{
25312531
sdf::Errors errors;
2532-
bool result = checkFrameAttachedToGraph(_root, errors);
2532+
bool result = checkFrameAttachedToGraph(errors, _root);
25332533
sdf::throwOrPrintErrors(errors);
25342534
return result;
25352535
}
25362536

25372537
//////////////////////////////////////////////////
2538-
bool checkFrameAttachedToGraph(const sdf::Root *_root, sdf::Errors &_errors)
2538+
bool checkFrameAttachedToGraph(sdf::Errors &_errors, const sdf::Root *_root)
25392539
{
25402540
bool result = true;
25412541

@@ -2622,13 +2622,13 @@ bool checkFrameAttachedToGraph(const sdf::Root *_root, sdf::Errors &_errors)
26222622
bool checkPoseRelativeToGraph(const sdf::Root *_root)
26232623
{
26242624
sdf::Errors errors;
2625-
bool result = checkPoseRelativeToGraph(_root, errors);
2625+
bool result = checkPoseRelativeToGraph(errors, _root);
26262626
sdf::throwOrPrintErrors(errors);
26272627
return result;
26282628
}
26292629

26302630
//////////////////////////////////////////////////
2631-
bool checkPoseRelativeToGraph(const sdf::Root *_root, sdf::Errors &_errors)
2631+
bool checkPoseRelativeToGraph(sdf::Errors &_errors, const sdf::Root *_root)
26322632
{
26332633
bool result = true;
26342634

test/integration/includes.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,14 +345,16 @@ TEST(IncludesTest, IncludeModelMissingConfig)
345345
sdf::Errors errors;
346346
ASSERT_TRUE(sdf::readString(stream.str(), sdfParsed, errors));
347347

348-
ASSERT_GE(1u, errors.size());
349-
EXPECT_EQ(1u, errors.size());
350-
EXPECT_EQ(errors[0].Code(), sdf::ErrorCode::URI_LOOKUP);
351-
EXPECT_NE(std::string::npos, errors[0].Message().find(
352-
"Unable to resolve uri[box_missing_config] to model path")) << errors[0];
348+
EXPECT_EQ(2u, errors.size());
349+
EXPECT_EQ(errors[0].Code(), sdf::ErrorCode::FILE_READ);
353350
EXPECT_NE(std::string::npos, errors[0].Message().find(
351+
"Could not find model.config or manifest.xml in")) << errors[0];
352+
EXPECT_EQ(errors[1].Code(), sdf::ErrorCode::URI_LOOKUP);
353+
EXPECT_NE(std::string::npos, errors[1].Message().find(
354+
"Unable to resolve uri[box_missing_config] to model path")) << errors[1];
355+
EXPECT_NE(std::string::npos, errors[1].Message().find(
354356
"box_missing_config] since it does not contain a model.config file"))
355-
<< errors[0];
357+
<< errors[1];
356358

357359
sdf::Root root;
358360
errors = root.Load(sdfParsed);

0 commit comments

Comments
 (0)