From 8086b71ea9d1f3fa1dac4d3ee05d0a7ae15ede56 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 7 May 2025 18:11:29 +0200 Subject: [PATCH 1/2] Only emit one error if capturing stdout goes wrong during assembler checkout --- .../Sourcing/RepositorySourcesFetcher.cs | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/tooling/docs-assembler/Sourcing/RepositorySourcesFetcher.cs b/src/tooling/docs-assembler/Sourcing/RepositorySourcesFetcher.cs index 743b3b198..0d2007f50 100644 --- a/src/tooling/docs-assembler/Sourcing/RepositorySourcesFetcher.cs +++ b/src/tooling/docs-assembler/Sourcing/RepositorySourcesFetcher.cs @@ -125,8 +125,6 @@ private bool TryUpdateSource(string name, string branch, string relativePath, ID _logger.LogInformation("Pull: {Name}\t{Branch}\t{RelativePath}", name, branch, relativePath); // --allow-unrelated-histories due to shallow clones not finding a common ancestor ExecIn(checkoutFolder, "git", "pull", "--depth", "1", "--allow-unrelated-histories", "--no-ff"); - head = Capture(checkoutFolder, "git", "rev-parse", "HEAD"); - return true; } catch (Exception e) { @@ -136,9 +134,12 @@ private bool TryUpdateSource(string name, string branch, string relativePath, ID checkoutFolder.Delete(true); checkoutFolder.Refresh(); } + return false; } - return false; + head = Capture(checkoutFolder, "git", "rev-parse", "HEAD"); + + return true; } private string CheckoutFromScratch(Repository repository, string name, string branch, string relativePath, @@ -183,19 +184,26 @@ private void ExecIn(IDirectoryInfo? workingDirectory, string binary, params stri // ReSharper disable once UnusedMember.Local private string Capture(IDirectoryInfo? workingDirectory, string binary, params string[] args) { - // Try 10 times to capture the output of the command, if it fails we'll throw an exception on the last try - for (var i = 0; i < 9; i++) + // Try 10 times to capture the output of the command, if it fails, we'll throw an exception on the last try + Exception? e = null; + for (var i = 0; i <= 9; i++) { try { return CaptureOutput(); } - catch + catch (Exception ex) { - // ignored + if (ex is not null) + e = ex; } } - return CaptureOutput(); + + if (e is not null) + collector.EmitError("", "failure capturing stdout", e); + + + return string.Empty; string CaptureOutput() { @@ -208,9 +216,9 @@ string CaptureOutput() ConsoleOutWriter = NoopConsoleWriter.Instance }; var result = Proc.Start(arguments); - if (result.ExitCode != 0) - collector.EmitError("", $"Exit code: {result.ExitCode} while executing {binary} {string.Join(" ", args)} in {workingDirectory}"); - var line = result.ConsoleOut.FirstOrDefault()?.Line ?? throw new Exception($"No output captured for {binary}: {workingDirectory}"); + var line = result.ExitCode != 0 + ? throw new Exception($"Exit code is nto 0 received {result.ExitCode} from {binary}: {workingDirectory}") + : result.ConsoleOut.FirstOrDefault()?.Line ?? throw new Exception($"No output captured for {binary}: {workingDirectory}"); return line; } } From 3e4e2e6e511b11bf0d765078b51604ae169a00c3 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 7 May 2025 18:15:32 +0200 Subject: [PATCH 2/2] Update src/tooling/docs-assembler/Sourcing/RepositorySourcesFetcher.cs Co-authored-by: Jan Calanog --- src/tooling/docs-assembler/Sourcing/RepositorySourcesFetcher.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tooling/docs-assembler/Sourcing/RepositorySourcesFetcher.cs b/src/tooling/docs-assembler/Sourcing/RepositorySourcesFetcher.cs index 0d2007f50..444b587c9 100644 --- a/src/tooling/docs-assembler/Sourcing/RepositorySourcesFetcher.cs +++ b/src/tooling/docs-assembler/Sourcing/RepositorySourcesFetcher.cs @@ -217,7 +217,7 @@ string CaptureOutput() }; var result = Proc.Start(arguments); var line = result.ExitCode != 0 - ? throw new Exception($"Exit code is nto 0 received {result.ExitCode} from {binary}: {workingDirectory}") + ? throw new Exception($"Exit code is not 0. Received {result.ExitCode} from {binary}: {workingDirectory}") : result.ConsoleOut.FirstOrDefault()?.Line ?? throw new Exception($"No output captured for {binary}: {workingDirectory}"); return line; }