Skip to content

Commit 8b50df6

Browse files
committed
Include node ID in the VerifyXML failure message
This should help users localize where the issue is, especially if they're using a UI to edit their behavior trees and not a text editor that has line numbers. This required moving the check for whether or not the ID is empty before the other checks.
1 parent 4ede94d commit 8b50df6

File tree

1 file changed

+41
-34
lines changed

1 file changed

+41
-34
lines changed

src/xml_parsing.cpp

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -431,67 +431,72 @@ void VerifyXML(const std::string& xml_text,
431431

432432
if(name == "Decorator")
433433
{
434-
if(children_count != 1)
435-
{
436-
ThrowError(line_number, "The tag <Decorator> must have exactly 1 "
437-
"child");
438-
}
439434
if(ID.empty())
440435
{
441436
ThrowError(line_number, "The tag <Decorator> must have the "
442437
"attribute [ID]");
443438
}
439+
if(children_count != 1)
440+
{
441+
ThrowError(line_number, "The tag <Decorator> with ID '" + ID +
442+
"' must have exactly 1 "
443+
"child");
444+
}
444445
}
445446
else if(name == "Action")
446447
{
447-
if(children_count != 0)
448-
{
449-
ThrowError(line_number, "The tag <Action> must not have any "
450-
"child");
451-
}
452448
if(ID.empty())
453449
{
454450
ThrowError(line_number, "The tag <Action> must have the "
455451
"attribute [ID]");
456452
}
457-
}
458-
else if(name == "Condition")
459-
{
460453
if(children_count != 0)
461454
{
462-
ThrowError(line_number, "The tag <Condition> must not have any "
463-
"child");
455+
ThrowError(line_number, "The tag <Action> with ID '" + ID +
456+
"' must not have any "
457+
"child");
464458
}
459+
}
460+
else if(name == "Condition")
461+
{
465462
if(ID.empty())
466463
{
467464
ThrowError(line_number, "The tag <Condition> must have the "
468465
"attribute [ID]");
469466
}
467+
if(children_count != 0)
468+
{
469+
ThrowError(line_number, "The tag <Condition> with ID '" + ID +
470+
"' must not have any "
471+
"child");
472+
}
470473
}
471474
else if(name == "Control")
472475
{
473-
if(children_count == 0)
474-
{
475-
ThrowError(line_number, "The tag <Control> must have at least 1 "
476-
"child");
477-
}
478476
if(ID.empty())
479477
{
480478
ThrowError(line_number, "The tag <Control> must have the "
481479
"attribute [ID]");
482480
}
481+
if(children_count == 0)
482+
{
483+
ThrowError(line_number, "The tag <Control> with ID '" + ID +
484+
"' must have at least 1 "
485+
"child");
486+
}
483487
}
484488
else if(name == "SubTree")
485489
{
486-
if(children_count != 0)
487-
{
488-
ThrowError(line_number, "<SubTree> should not have any child");
489-
}
490490
if(ID.empty())
491491
{
492492
ThrowError(line_number, "The tag <SubTree> must have the "
493493
"attribute [ID]");
494494
}
495+
if(children_count != 0)
496+
{
497+
ThrowError(line_number,
498+
"<SubTree> with ID '" + ID + "' should not have any child");
499+
}
495500
if(registered_nodes.count(ID) != 0)
496501
{
497502
ThrowError(line_number, "The attribute [ID] of tag <SubTree> must "
@@ -505,16 +510,17 @@ void VerifyXML(const std::string& xml_text,
505510
ThrowError(line_number, "The tag <BehaviorTree> must have the "
506511
"attribute [ID]");
507512
}
508-
if(children_count != 1)
509-
{
510-
ThrowError(line_number, "The tag <BehaviorTree> must have exactly 1 "
511-
"child");
512-
}
513513
if(registered_nodes.count(ID) != 0)
514514
{
515515
ThrowError(line_number, "The attribute [ID] of tag <BehaviorTree> "
516516
"must not use the name of a registered Node");
517517
}
518+
if(children_count != 1)
519+
{
520+
ThrowError(line_number, "The tag <BehaviorTree> with ID '" + ID +
521+
"' must have exactly 1 "
522+
"child");
523+
}
518524
}
519525
else
520526
{
@@ -530,16 +536,16 @@ void VerifyXML(const std::string& xml_text,
530536
{
531537
if(children_count != 1)
532538
{
533-
ThrowError(line_number,
534-
std::string("The node <") + name + "> must have exactly 1 child");
539+
ThrowError(line_number, std::string("The node <") + name + "> with ID '" + ID +
540+
"' must have exactly 1 child");
535541
}
536542
}
537543
else if(search->second == NodeType::CONTROL)
538544
{
539545
if(children_count == 0)
540546
{
541-
ThrowError(line_number,
542-
std::string("The node <") + name + "> must have 1 or more children");
547+
ThrowError(line_number, std::string("The node <") + name + "> with ID '" + ID +
548+
"' must have 1 or more children");
543549
}
544550
if(name == "ReactiveSequence")
545551
{
@@ -563,7 +569,8 @@ void VerifyXML(const std::string& xml_text,
563569
++async_count;
564570
if(async_count > 1)
565571
{
566-
ThrowError(line_number, std::string("A ReactiveSequence cannot have more "
572+
ThrowError(line_number, std::string("A ReactiveSequence with ID '" + ID +
573+
"' cannot have more "
567574
"than one async child."));
568575
}
569576
}

0 commit comments

Comments
 (0)