pgraph: Print cycles on error

I'm a terrible algorithmist, so who knows if this is correct, but it
seems to work in my cursory testing.
This commit is contained in:
James Shubin
2025-06-25 04:51:33 -04:00
parent a4ed647d02
commit 0a79daf277
3 changed files with 134 additions and 5 deletions

View File

@@ -291,7 +291,14 @@ func (obj *Interpreter) Interpret(ast interfaces.Stmt, table map[interfaces.Func
// ensure that we have a DAG!
if _, err := graph.TopologicalSort(); err != nil {
// TODO: print information on the cycles
errNotAcyclic, ok := err.(*pgraph.ErrNotAcyclic)
if !ok {
return nil, err // programming error
}
obj.Logf("%s", err)
for _, vertex := range errNotAcyclic.Cycle {
obj.Logf("* %s", vertex)
}
return nil, errwrap.Wrapf(err, "resource graph has cycles")
}