This commit is contained in:
2026-10-21 21:01:47 -04:00
parent e6604564a7
commit aea80c7be4
6 changed files with 131 additions and 7 deletions
+11 -3
View File
@@ -367,11 +367,19 @@ function Save-OfficeDownload {
$null = Write-Output "Download attempt ${attempt}: $Uri -> $Path"
Invoke-WebRequest -UseBasicParsing -Uri $Uri -OutFile $Path -TimeoutSec $TimeoutSeconds -ErrorAction Stop
if ((Get-Item -LiteralPath $Path -ErrorAction Stop).Length -eq 0) { throw 'Download was empty.' }
if ($attempt -gt 1) { $null = Write-Output "Download recovered on attempt ${attempt}: $Uri -> $Path" }
return
} catch {
Write-Error "Download attempt $attempt failed: $($_.Exception.Message)" -ErrorAction Continue
if ($attempt -eq $definitions.DownloadAttempts) { throw }
Start-Sleep -Seconds ($definitions.DownloadRetrySeconds * $attempt)
$reason = $_.Exception.Message
if ($attempt -eq $definitions.DownloadAttempts) {
# The entry point logs and reports the terminal error once to Syncro.
throw "Download failed after $attempt attempts: $Uri -> $Path. $reason"
}
$delay = $definitions.DownloadRetrySeconds * $attempt
# Tools.ps1 logs Write-Output; suppress its echo so a recoverable attempt
# neither pollutes return values nor produces an error in Syncro.
$null = Write-Output "Download attempt $attempt of $($definitions.DownloadAttempts) failed for $Uri -> $Path. $reason Retrying in $delay seconds."
Start-Sleep -Seconds $delay
}
}
}