@@ -33,15 +33,15 @@ public class GoComponentDetector : FileComponentDetector
33
33
34
34
public override IEnumerable < ComponentType > SupportedComponentTypes { get ; } = new [ ] { ComponentType . Go } ;
35
35
36
- public override int Version => 3 ;
36
+ public override int Version => 4 ;
37
37
38
38
private HashSet < string > projectRoots = new HashSet < string > ( ) ;
39
39
40
40
protected override async Task OnFileFound ( ProcessRequest processRequest , IDictionary < string , string > detectorArgs )
41
41
{
42
42
var singleFileComponentRecorder = processRequest . SingleFileComponentRecorder ;
43
43
var file = processRequest . ComponentStream ;
44
-
44
+
45
45
var projectRootDirectory = Directory . GetParent ( file . Location ) ;
46
46
if ( projectRoots . Any ( path => projectRootDirectory . FullName . StartsWith ( path ) ) )
47
47
{
@@ -57,9 +57,10 @@ protected override async Task OnFileFound(ProcessRequest processRequest, IDictio
57
57
wasGoCliScanSuccessful = await UseGoCliToScan ( file . Location , singleFileComponentRecorder ) ;
58
58
}
59
59
}
60
- catch
60
+ catch ( Exception ex )
61
61
{
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 ) ;
63
64
}
64
65
finally
65
66
{
@@ -231,7 +232,12 @@ private void PopulateDependencyGraph(string goGraphOutput, ISingleFileComponentR
231
232
}
232
233
else if ( isParentParsed && isChildParsed )
233
234
{
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
+
235
241
singleFileComponentRecorder . RegisterUsage ( new DetectedComponent ( childComponent ) , parentComponentId : parentComponent . Id ) ;
236
242
}
237
243
else
0 commit comments