Skip to content

Commit 88c1bda

Browse files
committed
fix to order from
1 parent ffc1af7 commit 88c1bda

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

‎src/skills/dep_graph.cpp‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "skills/dep_graph.h"
44
#include <algorithm> // for std::find
5+
#include <functional> // for std::function
56

67
bool DepGraph::add_node(const std::string& name) {
78

@@ -98,11 +99,16 @@ bool DepGraph::order_from(const std::string& root, std::vector<std::string>* out
9899
auto it = std::find(path.begin(), path.end(), node);
99100
if (it != path.end()) {
100101
*error = "cycle: ";
102+
103+
// Append the cycle path from the first occurrence of the node to the end of the path
101104
for (; it != path.end(); ++it) {
102-
if (it != path.begin()) *error += " -> ";
103105
*error += *it;
106+
*error += " -> ";
104107
}
105-
*error += " -> " + node;
108+
*error += node;
109+
110+
111+
106112
}
107113
return false;
108114
}
@@ -117,7 +123,7 @@ bool DepGraph::order_from(const std::string& root, std::vector<std::string>* out
117123
// Visit all requirements (edges) of the current node
118124
for (const auto& req : requirements(node)) {
119125
if (!has_node(req)) {
120-
*error = "unknown: " + req;
126+
*error = "missing: " + req + " (required by " + node + ")"; // Report missing dependency and which node requires it
121127
return false;
122128
}
123129
if (!dfs(req)) {
@@ -133,6 +139,8 @@ bool DepGraph::order_from(const std::string& root, std::vector<std::string>* out
133139
};
134140

135141

142+
out->clear(); // Clear the output vector before starting DFS
143+
136144
// Start DFS from the root node
137145
if (!dfs(root)) {
138146
return false;

0 commit comments

Comments
 (0)