Skip to content

Commit f387170

Browse files
Fix ProgressPreference restore on early throw; add -ErrorAction Stop to Invoke-WebRequest for retry reliability
- Move $previousProgressPreference assignment before the admin-rights check so it is always initialized when the clean block runs (prevents restore if the function throws before reaching the original assignment) - Add -ErrorAction Stop to both Invoke-WebRequest calls (parallel and sequential paths) so non-terminating HTTP/network errors are reliably caught by the retry try/catch loop
1 parent 729b884 commit f387170

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/functions/public/Install-GoogleFont.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ function Install-GoogleFont {
7070
)
7171

7272
begin {
73+
$previousProgressPreference = $ProgressPreference
7374
if ($Scope -eq 'AllUsers' -and -not (Test-Admin)) {
7475
$errorMessage = @'
7576
Administrator rights are required to install fonts.
7677
Please run the command again with elevated rights (Run as Administrator) or provide '-Scope CurrentUser' to your command.
7778
'@
7879
throw $errorMessage
7980
}
80-
$previousProgressPreference = $ProgressPreference
8181
$googleFontsToInstall = [System.Collections.Generic.List[object]]::new()
8282
$seenUrls = [System.Collections.Generic.HashSet[string]]::new([System.StringComparer]::OrdinalIgnoreCase)
8383

@@ -225,7 +225,7 @@ Please run the command again with elevated rights (Run as Administrator) or prov
225225
$currentProgressPreference = $ProgressPreference
226226
$ProgressPreference = 'SilentlyContinue'
227227
try {
228-
Invoke-WebRequest -Uri $item.URL -OutFile $item.DownloadPath
228+
Invoke-WebRequest -Uri $item.URL -OutFile $item.DownloadPath -ErrorAction Stop
229229
} finally {
230230
$ProgressPreference = $currentProgressPreference
231231
}
@@ -263,7 +263,7 @@ Please run the command again with elevated rights (Run as Administrator) or prov
263263
$currentProgressPreference = $ProgressPreference
264264
$ProgressPreference = 'SilentlyContinue'
265265
try {
266-
Invoke-WebRequest -Uri $item.URL -OutFile $item.DownloadPath
266+
Invoke-WebRequest -Uri $item.URL -OutFile $item.DownloadPath -ErrorAction Stop
267267
} finally {
268268
$ProgressPreference = $currentProgressPreference
269269
}

0 commit comments

Comments
 (0)