@@ -81,6 +81,11 @@ func moduleKeyDisplay(key string) string {
8181 return display
8282}
8383
84+ func moduleDisplayName (key string ) string {
85+ display := filepath .ToSlash (moduleKeyDisplay (key ))
86+ return strings .TrimSuffix (display , ".vibe" )
87+ }
88+
8489func moduleRelativePath (root , fullPath string ) (string , error ) {
8590 rel , err := moduleRelativePathLexical (root , fullPath )
8691 if err != nil {
@@ -336,9 +341,19 @@ func moduleCycleFromExecution(stack []moduleContext, next string) ([]string, boo
336341}
337342
338343func formatModuleCycle (cycle []string ) string {
339- parts := make ([]string , len (cycle ))
340- for idx , key := range cycle {
341- parts [idx ] = moduleKeyDisplay (key )
344+ if len (cycle ) == 0 {
345+ return ""
346+ }
347+ normalized := make ([]string , 0 , len (cycle ))
348+ for _ , key := range cycle {
349+ if len (normalized ) > 0 && normalized [len (normalized )- 1 ] == key {
350+ continue
351+ }
352+ normalized = append (normalized , key )
353+ }
354+ parts := make ([]string , len (normalized ))
355+ for idx , key := range normalized {
356+ parts [idx ] = moduleDisplayName (key )
342357 }
343358 return strings .Join (parts , " -> " )
344359}
@@ -485,7 +500,8 @@ func builtinRequire(exec *Execution, receiver Value, args []Value, kwargs map[st
485500 }
486501
487502 if exec .moduleLoading [entry .key ] {
488- return NewNil (), fmt .Errorf ("require: circular dependency detected for module %q" , moduleKeyDisplay (entry .key ))
503+ cycle := append (append ([]string (nil ), exec .moduleLoadStack ... ), entry .key )
504+ return NewNil (), fmt .Errorf ("require: circular dependency detected: %s" , formatModuleCycle (cycle ))
489505 }
490506 exec .moduleLoading [entry .key ] = true
491507 exec .moduleLoadStack = append (exec .moduleLoadStack , entry .key )
0 commit comments