Skip to content

Commit 4905552

Browse files
committed
using a custom error message for package download failure
1 parent 79ad802 commit 4905552

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

internal/functions/Install-NugetPackage.ps1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,13 @@ function Install-NugetPackage {
9595

9696
$baseAddressUrl = $index.resources | Where-Object { $_.'@type' -eq 'PackageBaseAddress/3.0.0' } | Select-Object -First 1
9797
$downloadUrl = "$($baseAddressUrl.'@id')$packageLowerName/$selectedVersion/$fileName"
98-
Invoke-WebRequest -Uri $downloadUrl -OutFile $packagePath -ErrorAction Stop
98+
try {
99+
Invoke-WebRequest -Uri $downloadUrl -OutFile $packagePath -ErrorAction Stop
100+
}
101+
catch {
102+
$originalError = $_.Exception.Message
103+
Stop-PSFFunction -Message "Failed to download from $downloadUrl`: $originalError" -EnableException $true
104+
}
99105
Write-PSFMessage -Level Verbose -Message "Extracting $fileName to $folder"
100106
if ($isCoreCLR) {
101107
[System.IO.Compression.ZipFile]::ExtractToDirectory($packagePath, $folder, $true)

tests/integration/Install-NugetPackage.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Describe "Install-NugetPackage tests" -Tag IntegrationTests {
4040
It "should attempt to install $d libraries for a wrong version" {
4141
$dependencies = Get-ExternalLibrary -Type $Type
4242
foreach ($package in $dependencies) {
43-
{ Install-NugetPackage -Name $package.Name -RequiredVersion "0.somerandomversion" -Scope CurrentUser -Force -Confirm:$false } | Should -Throw '*Not Found*'
43+
{ Install-NugetPackage -Name $package.Name -RequiredVersion "0.somerandomversion" -Scope CurrentUser -Force -Confirm:$false } | Should -Throw 'Failed to download*'
4444
{ Install-NugetPackage -Name $package.Name -MinimumVersion "10.0" -MaximumVersion "1.0" -Scope CurrentUser -Force -Confirm:$false } | Should -Throw '*Version could not be found*'
4545
}
4646
}

0 commit comments

Comments
 (0)