@@ -119,6 +119,7 @@ class BehaviorTreeHandler
119119 kXmlExtension .size (), kXmlExtension ) != 0 );
120120
121121 std::set<std::string> registered_ids;
122+ std::vector<std::string> conflicting_files;
122123 std::string main_id;
123124
124125 auto register_all_bt_files = [&](const std::string & skip_file = " " ) {
@@ -137,8 +138,7 @@ class BehaviorTreeHandler
137138 continue ;
138139 }
139140 if (registered_ids.count (id)) {
140- std::cerr << " Skipping conflicting BT file " << entry.path () << " (duplicate ID " <<
141- id << " )" << " \n " ;
141+ conflicting_files.push_back (entry.path ().string ());
142142 continue ;
143143 }
144144 std::cout << " Registering Tree from File: " << entry.path ().string () << " \n " ;
@@ -169,6 +169,20 @@ class BehaviorTreeHandler
169169 register_all_bt_files ();
170170 }
171171
172+ // Log all conflicting files once at the end
173+ if (!conflicting_files.empty ()) {
174+ std::string files_list;
175+ for (const auto & file : conflicting_files) {
176+ if (!files_list.empty ()) {
177+ files_list += " , " ;
178+ }
179+ files_list += file;
180+ }
181+ std::cerr << " Skipping conflicting BT XML files, multiple files have the same ID. "
182+ << " Please set unique behavior tree IDs. This may affect loading of subtrees. "
183+ << " Files not loaded: " << files_list << " \n " ;
184+ }
185+
172186 // Create the tree with the specified ID
173187 blackboard = setBlackboardVariables ();
174188 try {
@@ -437,15 +451,18 @@ TEST_F(BehaviorTreeTestFixture, TestDuplicateIDsWithFileSpecified) {
437451
438452 EXPECT_TRUE (result);
439453
440- bool found_conflict =
441- log_output.find (
442- " Skipping conflicting BT file \" " + dup2_file +
443- " \" (duplicate ID DuplicateTree)" ) != std::string::npos;
444- EXPECT_TRUE (found_conflict);
454+ // Verify the new message format
455+ EXPECT_NE (
456+ log_output.find (" Skipping conflicting BT XML files, multiple files have the same ID." ),
457+ std::string::npos) << " Should warn about duplicate IDs" ;
458+ EXPECT_NE (log_output.find (" Please set unique behavior tree IDs" ), std::string::npos)
459+ << " Should provide guidance about unique IDs" ;
460+ EXPECT_NE (log_output.find (" Files not loaded:" ), std::string::npos)
461+ << " Should list files not loaded" ;
462+ EXPECT_NE (log_output.find (dup2_file), std::string::npos)
463+ << " Should mention the skipped file" ;
445464
446465 EXPECT_NE (log_output.find (" Registering Tree from File" ), std::string::npos);
447- EXPECT_NE (log_output.find (" Skipping conflicting BT file" ), std::string::npos)
448- << " Should warn about duplicate ID" ;
449466 EXPECT_NE (log_output.find (" Created BT from ID: DuplicateTree" ), std::string::npos);
450467
451468 std::filesystem::remove_all (tmp_dir);
@@ -590,7 +607,7 @@ TEST_F(BehaviorTreeTestFixture, TestDuplicateIDsWithIDSpecified) {
590607
591608 EXPECT_NE (log_output.find (" Registering Tree from File" ), std::string::npos)
592609 << " Should have registered at least one BT file" ;
593- EXPECT_NE (log_output.find (" Skipping conflicting BT file " ), std::string::npos)
610+ EXPECT_NE (log_output.find (" Skipping conflicting BT XML files " ), std::string::npos)
594611 << " Should warn about duplicate IDs" ;
595612 EXPECT_NE (log_output.find (" Created BT from ID: DuplicateTree" ), std::string::npos)
596613 << " Should have created BT from the given ID" ;
@@ -604,7 +621,7 @@ TEST_F(BehaviorTreeTestFixture, TestDuplicateIDsWithIDSpecified) {
604621 << " At least one duplicate file should have been registered" ;
605622 EXPECT_FALSE (registered_dup1 && registered_dup2)
606623 << " Only one of the duplicate files should be registered as the main tree" ;
607- EXPECT_NE (log_output.find (" Skipping conflicting BT file " ), std::string::npos);
624+ EXPECT_NE (log_output.find (" Skipping conflicting BT XML files " ), std::string::npos);
608625 EXPECT_NE (log_output.find (" Created BT from ID: DuplicateTree" ), std::string::npos);
609626
610627
0 commit comments