From 3b655e142555ce3bbbe669515654d9a24b0a819b Mon Sep 17 00:00:00 2001 From: Tony Redondo Date: Thu, 21 Nov 2024 16:34:09 +0100 Subject: [PATCH] [CI Visibility] Catch `UploadRepositoryChanges` exceptions (#6331) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary of changes This PR adds some missing try/catch for the UploadRepositoryChanges calls. ## Reason for change This method is being used in the `dd-trace` runner, currently if the method fails (backend error) then `dd-trace` will throw an exception. ## Implementation details We create a function method to wrap the call with a try/catch block so we don't throw and fail the customer CI. ## Test coverage ## Other details --- tracer/src/Datadog.Trace.Tools.Runner/CiUtils.cs | 14 +++++++++++++- tracer/src/Datadog.Trace/Ci/CIVisibility.cs | 16 ++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/tracer/src/Datadog.Trace.Tools.Runner/CiUtils.cs b/tracer/src/Datadog.Trace.Tools.Runner/CiUtils.cs index 1991cb20d96b..841eaf4ff386 100644 --- a/tracer/src/Datadog.Trace.Tools.Runner/CiUtils.cs +++ b/tracer/src/Datadog.Trace.Tools.Runner/CiUtils.cs @@ -139,7 +139,19 @@ public static async Task InitializeCiCommandsAsync( if (ciVisibilitySettings.GitUploadEnabled != false || ciVisibilitySettings.IntelligentTestRunnerEnabled) { // If we are in git upload only then we can defer the await until the child command exits. - uploadRepositoryChangesTask = Task.Run(() => lazyItrClient.Value.UploadRepositoryChangesAsync()); + async Task UploadRepositoryChangesAsync() + { + try + { + await lazyItrClient.Value.UploadRepositoryChangesAsync().ConfigureAwait(false); + } + catch (Exception ex) + { + Log.Error(ex, "RunCiCommand: Error uploading repository git metadata."); + } + } + + uploadRepositoryChangesTask = Task.Run(UploadRepositoryChangesAsync); // Once the repository has been uploaded we switch off the git upload in children processes profilerEnvironmentVariables[Configuration.ConfigurationKeys.CIVisibility.GitUploadEnabled] = "0"; diff --git a/tracer/src/Datadog.Trace/Ci/CIVisibility.cs b/tracer/src/Datadog.Trace/Ci/CIVisibility.cs index 795ac4719398..949ef3b10510 100644 --- a/tracer/src/Datadog.Trace/Ci/CIVisibility.cs +++ b/tracer/src/Datadog.Trace/Ci/CIVisibility.cs @@ -708,11 +708,23 @@ private static async Task GetIntelligentTestRunnerSkippableTestsAsync() var settings = Settings; var lazyItrClient = new Lazy(() => new(CIEnvironmentValues.Instance.WorkspacePath, settings)); - Task? uploadRepositoryChangesTask = null; + Task? uploadRepositoryChangesTask = null; if (settings.GitUploadEnabled != false) { // Upload the git metadata - uploadRepositoryChangesTask = Task.Run(() => lazyItrClient.Value.UploadRepositoryChangesAsync()); + async Task UploadRepositoryChangesAsync() + { + try + { + await lazyItrClient.Value.UploadRepositoryChangesAsync().ConfigureAwait(false); + } + catch (Exception ex) + { + Log.Error(ex, "CIVisibility: Error uploading repository git metadata."); + } + } + + uploadRepositoryChangesTask = Task.Run(UploadRepositoryChangesAsync); } // If any DD_CIVISIBILITY_CODE_COVERAGE_ENABLED or DD_CIVISIBILITY_TESTSSKIPPING_ENABLED has not been set