@@ -33,15 +33,15 @@ public class GoComponentDetector : FileComponentDetector
3333
3434 public override IEnumerable < ComponentType > SupportedComponentTypes { get ; } = new [ ] { ComponentType . Go } ;
3535
36- public override int Version => 3 ;
36+ public override int Version => 4 ;
3737
3838 private HashSet < string > projectRoots = new HashSet < string > ( ) ;
3939
4040 protected override async Task OnFileFound ( ProcessRequest processRequest , IDictionary < string , string > detectorArgs )
4141 {
4242 var singleFileComponentRecorder = processRequest . SingleFileComponentRecorder ;
4343 var file = processRequest . ComponentStream ;
44-
44+
4545 var projectRootDirectory = Directory . GetParent ( file . Location ) ;
4646 if ( projectRoots . Any ( path => projectRootDirectory . FullName . StartsWith ( path ) ) )
4747 {
@@ -57,9 +57,10 @@ protected override async Task OnFileFound(ProcessRequest processRequest, IDictio
5757 wasGoCliScanSuccessful = await UseGoCliToScan ( file . Location , singleFileComponentRecorder ) ;
5858 }
5959 }
60- catch
60+ catch ( Exception ex )
6161 {
62- Logger . LogInfo ( "Failed to detect components using go cli." ) ;
62+ Logger . LogError ( $ "Failed to detect components using go cli. Location: { file . Location } ") ;
63+ Logger . LogException ( ex , isError : true , printException : true ) ;
6364 }
6465 finally
6566 {
@@ -231,7 +232,12 @@ private void PopulateDependencyGraph(string goGraphOutput, ISingleFileComponentR
231232 }
232233 else if ( isParentParsed && isChildParsed )
233234 {
234- // Go output guarantees that all parents will be output before children
235+ // Go can have a cyclic dependency between modules, which could cause child components to be listed first than parents. Reproducible with Go 1.16
236+ if ( singleFileComponentRecorder . GetComponent ( parentComponent . Id ) == null )
237+ {
238+ singleFileComponentRecorder . RegisterUsage ( new DetectedComponent ( parentComponent ) ) ;
239+ }
240+
235241 singleFileComponentRecorder . RegisterUsage ( new DetectedComponent ( childComponent ) , parentComponentId : parentComponent . Id ) ;
236242 }
237243 else
0 commit comments