From eaf7a6d53b752e172d99aef9497850fe2c05cdc6 Mon Sep 17 00:00:00 2001 From: Amitla Vannikumar Date: Fri, 11 Oct 2024 15:38:28 -0700 Subject: [PATCH 1/3] handle version exceptions --- .../Records/GoReplaceTelemetryRecord.cs | 2 ++ .../go/GoComponentDetector.cs | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/GoReplaceTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/GoReplaceTelemetryRecord.cs index f9fa2320c..2edbd9684 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/GoReplaceTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/GoReplaceTelemetryRecord.cs @@ -7,4 +7,6 @@ public class GoReplaceTelemetryRecord : BaseDetectionTelemetryRecord public string GoModPathAndVersion { get; set; } public string GoModReplacement { get; set; } + + public string ExceptionMessage { get; set; } } diff --git a/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs index aa7eacdf0..c06734d5d 100644 --- a/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs @@ -476,11 +476,19 @@ private void RecordBuildDependencies(string goListOutput, ISingleFileComponentRe GoComponent goComponent; if (dependency.Replace?.Path != null && dependency.Replace.Version != null) { - var dependencyReplacementName = $"{dependency.Replace.Path} {dependency.Replace.Version}"; - goComponent = new GoComponent(dependency.Replace.Path, dependency.Replace.Version); - this.Logger.LogInformation("go Module {GoModule} being replaced with module {GoModuleReplacement}", dependencyName, dependencyReplacementName); - record.GoModPathAndVersion = dependencyName; - record.GoModReplacement = dependencyReplacementName; + try + { + var dependencyReplacementName = $"{dependency.Replace.Path} {dependency.Replace.Version}"; + goComponent = new GoComponent(dependency.Replace.Path, dependency.Replace.Version); + this.Logger.LogInformation("go Module {GoModule} being replaced with module {GoModuleReplacement}", dependencyName, dependencyReplacementName); + record.GoModPathAndVersion = dependencyName; + record.GoModReplacement = dependencyReplacementName; + } + catch (Exception ex) + { + record.ExceptionMessage = ex.Message; + goComponent = new GoComponent(dependency.Path, dependency.Version); + } } else { From 65619e648256910d59c8ef61bf0e99a402d1f8e2 Mon Sep 17 00:00:00 2001 From: Amitla Vannikumar Date: Mon, 14 Oct 2024 12:18:25 -0700 Subject: [PATCH 2/3] adding log warning --- .../go/GoComponentDetector.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs index c06734d5d..dfcefb129 100644 --- a/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs @@ -487,6 +487,7 @@ private void RecordBuildDependencies(string goListOutput, ISingleFileComponentRe catch (Exception ex) { record.ExceptionMessage = ex.Message; + this.Logger.LogWarning("tried to use replace module but got this error {ErrorMessage} using original module instead", ex.Message); goComponent = new GoComponent(dependency.Path, dependency.Version); } } From bd7f5b77833f44c389ea318d7776e4fcf9e73b43 Mon Sep 17 00:00:00 2001 From: Amitla Vannikumar Date: Mon, 14 Oct 2024 15:00:27 -0700 Subject: [PATCH 3/3] adding module names --- .../go/GoComponentDetector.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs index dfcefb129..5d9e3051e 100644 --- a/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs @@ -476,18 +476,18 @@ private void RecordBuildDependencies(string goListOutput, ISingleFileComponentRe GoComponent goComponent; if (dependency.Replace?.Path != null && dependency.Replace.Version != null) { + var dependencyReplacementName = $"{dependency.Replace.Path} {dependency.Replace.Version}"; + record.GoModPathAndVersion = dependencyName; + record.GoModReplacement = dependencyReplacementName; try { - var dependencyReplacementName = $"{dependency.Replace.Path} {dependency.Replace.Version}"; goComponent = new GoComponent(dependency.Replace.Path, dependency.Replace.Version); this.Logger.LogInformation("go Module {GoModule} being replaced with module {GoModuleReplacement}", dependencyName, dependencyReplacementName); - record.GoModPathAndVersion = dependencyName; - record.GoModReplacement = dependencyReplacementName; } catch (Exception ex) { record.ExceptionMessage = ex.Message; - this.Logger.LogWarning("tried to use replace module but got this error {ErrorMessage} using original module instead", ex.Message); + this.Logger.LogWarning("tried to use replace module {GoModuleReplacement} but got this error {ErrorMessage} using original module {GoModule} instead", dependencyReplacementName, ex.Message, dependencyName); goComponent = new GoComponent(dependency.Path, dependency.Version); } }