Skip to content

Commit ae28751

Browse files
amitla1Amitla Vannikumar
andauthored
Handle Go Replace Exceptions (#1273)
* handle version exceptions * adding log warning * adding module names --------- Co-authored-by: Amitla Vannikumar <[email protected]>
1 parent 96cc922 commit ae28751

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/Microsoft.ComponentDetection.Common/Telemetry/Records/GoReplaceTelemetryRecord.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ public class GoReplaceTelemetryRecord : BaseDetectionTelemetryRecord
77
public string GoModPathAndVersion { get; set; }
88

99
public string GoModReplacement { get; set; }
10+
11+
public string ExceptionMessage { get; set; }
1012
}

src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,19 @@ private void RecordBuildDependencies(string goListOutput, ISingleFileComponentRe
477477
if (dependency.Replace?.Path != null && dependency.Replace.Version != null)
478478
{
479479
var dependencyReplacementName = $"{dependency.Replace.Path} {dependency.Replace.Version}";
480-
goComponent = new GoComponent(dependency.Replace.Path, dependency.Replace.Version);
481-
this.Logger.LogInformation("go Module {GoModule} being replaced with module {GoModuleReplacement}", dependencyName, dependencyReplacementName);
482480
record.GoModPathAndVersion = dependencyName;
483481
record.GoModReplacement = dependencyReplacementName;
482+
try
483+
{
484+
goComponent = new GoComponent(dependency.Replace.Path, dependency.Replace.Version);
485+
this.Logger.LogInformation("go Module {GoModule} being replaced with module {GoModuleReplacement}", dependencyName, dependencyReplacementName);
486+
}
487+
catch (Exception ex)
488+
{
489+
record.ExceptionMessage = ex.Message;
490+
this.Logger.LogWarning("tried to use replace module {GoModuleReplacement} but got this error {ErrorMessage} using original module {GoModule} instead", dependencyReplacementName, ex.Message, dependencyName);
491+
goComponent = new GoComponent(dependency.Path, dependency.Version);
492+
}
484493
}
485494
else
486495
{

0 commit comments

Comments
 (0)