Skip to content

Commit

Permalink
Handle Go Replace Exceptions (#1273)
Browse files Browse the repository at this point in the history
* handle version exceptions

* adding log warning

* adding module names

---------

Co-authored-by: Amitla Vannikumar <avannikumar@microsoft.com>
  • Loading branch information
amitla1 and Amitla Vannikumar authored Oct 14, 2024
1 parent 96cc922 commit ae28751
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ public class GoReplaceTelemetryRecord : BaseDetectionTelemetryRecord
public string GoModPathAndVersion { get; set; }

public string GoModReplacement { get; set; }

public string ExceptionMessage { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,19 @@ private void RecordBuildDependencies(string goListOutput, ISingleFileComponentRe
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
{
goComponent = new GoComponent(dependency.Replace.Path, dependency.Replace.Version);
this.Logger.LogInformation("go Module {GoModule} being replaced with module {GoModuleReplacement}", dependencyName, dependencyReplacementName);
}
catch (Exception ex)
{
record.ExceptionMessage = 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);
}
}
else
{
Expand Down

0 comments on commit ae28751

Please sign in to comment.