Skip to content

Commit 2d3357d

Browse files
authored
Refactor error handling in DeployWorkstation.ps1
1 parent 4da4b23 commit 2d3357d

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

DeployWorkstation.ps1

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -860,9 +860,17 @@ function Install-StandardApps {
860860
-1978334966, # 0x8A15010A winget network timeout
861861
-2147012887, # 0x80072EE9 connection reset by peer
862862
-2147012873, # 0x80072EF7 DNS name not resolved
863-
-2147012867 # 0x80072EFD connection refused
863+
-2147012867, # 0x80072EFD connection refused
864+
-2147012889 # 0x80072EE7 InternetOpenUrl failed / WinHTTP unknown error
864865
)
865-
$maxRetries = 2
866+
867+
# Known permanent failure codes — not retried, shown with a friendly message
868+
$knownFailMessages = @{
869+
-1978335215 = 'Installer hash mismatch (try again later or check proxy/AV)' # 0x8A150011
870+
-1978334960 = 'Installer blocked by security policy' # 0x8A150110
871+
-1978335132 = 'Installer requires reboot before proceeding' # 0x8A150064
872+
}
873+
$maxRetries = 2
866874
$retryDelaySec = 10
867875

868876
$appsToInstall = @(
@@ -929,12 +937,20 @@ function Install-StandardApps {
929937
Add-Result -Section (T 'PhaseApps') -Item $app.Name -Status 'OK' -Detail (T 'AlreadyInstalled')
930938
$script:Summary.AppsInstalled++
931939
} else {
932-
Write-Log "$(T 'InstallFail'): $($app.Name) - exit code $exitCode" -Level 'WARN'
933-
# Log last few lines of winget output to aid diagnosis.
934-
# 2>&1 can produce ErrorRecord objects alongside strings — coerce to string first.
940+
# Resolve a friendly reason — use known message or fall back to exit code
941+
$failReason = if ($knownFailMessages.ContainsKey($exitCode)) {
942+
$knownFailMessages[$exitCode]
943+
} else {
944+
"Exit code $exitCode"
945+
}
946+
Write-Log "$(T 'InstallFail'): $($app.Name) - $failReason" -Level 'WARN'
947+
# Log last clean lines of winget output — strip progress-bar/non-printable chars
935948
$diagLines = ($wingetOut | Where-Object { "$_".Trim() }) | Select-Object -Last 5
936-
foreach ($line in $diagLines) { Write-Log " $line" -Level 'WARN' }
937-
Add-Result -Section (T 'PhaseApps') -Item $app.Name -Status 'WARN' -Detail "Exit code $exitCode"
949+
foreach ($line in $diagLines) {
950+
$clean = ("$line" -replace '[^\x20-\x7E]', '').Trim()
951+
if ($clean.Length -gt 3) { Write-Log " $clean" -Level 'WARN' }
952+
}
953+
Add-Result -Section (T 'PhaseApps') -Item $app.Name -Status 'WARN' -Detail $failReason
938954
$script:Summary.AppsFailed++
939955
}
940956
}

0 commit comments

Comments
 (0)