From 706e2257809891af0188eee726568267af21c4cc Mon Sep 17 00:00:00 2001 From: David Paulson Date: Tue, 26 Nov 2024 20:39:31 -0600 Subject: [PATCH] Allow exceptions to be displayed for ScriptUpdateOnly param Correctly log the exceptions to avoid emailing in regarding an exception that is handled --- Diagnostics/HealthChecker/HealthChecker.ps1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Diagnostics/HealthChecker/HealthChecker.ps1 b/Diagnostics/HealthChecker/HealthChecker.ps1 index bef960c863..d15dd2306d 100644 --- a/Diagnostics/HealthChecker/HealthChecker.ps1 +++ b/Diagnostics/HealthChecker/HealthChecker.ps1 @@ -258,11 +258,23 @@ begin { if ($ScriptUpdateOnly) { Invoke-SetOutputInstanceLocation -FileName "HealthChecker-ScriptUpdateOnly" + $currentErrors = $Error.Count switch (Test-ScriptVersion -AutoUpdate -VersionsUrl "https://aka.ms/HC-VersionsUrl" -Confirm:$false) { ($true) { Write-Green("Script was successfully updated.") } ($false) { Write-Yellow("No update of the script performed.") } default { Write-Red("Unable to perform ScriptUpdateOnly operation.") } } + + if ($currentErrors -ne $Error.Count) { + Write-Host "" + Write-Warning "Failed to get latest version of script details. Failing with this inner exception:" + Write-Host "" + $Error[$Error.Count - $currentErrors - 1] | Out-String | Write-Host -ForegroundColor Red + Write-Host "" + Write-Host "Address the above exception in order to get the script to auto update." + } + + Invoke-ErrorCatchActionLoopFromIndex $currentErrors return }