Skip to content

Commit 4383fc7

Browse files
Merge branch 'main' into update-manifest
2 parents dc5eab2 + 7f3a700 commit 4383fc7

File tree

5 files changed

+40
-12
lines changed

5 files changed

+40
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.0.2] - 2023-01-22
8+
#### Fixed
9+
Source management error handling no longer references missing function
10+
711
## [0.0.1] - 2023-01-21
812
Initial release

src/AnyPackage.Chocolatey.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@{
22
RootModule = 'AnyPackage.Chocolatey.psm1'
3-
ModuleVersion = '0.0.1'
3+
ModuleVersion = '0.0.2'
44
CompatiblePSEditions = @('Desktop', 'Core')
55
GUID = '070f2b8f-c7db-4566-9296-2f7cc9146bf0'
66
Author = 'Ethan Bergstrom'

src/private/Find-ChocoPackage.ps1

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ function Find-ChocoPackage {
1414
# Found the matched registered source
1515
$Request.Source
1616
} else {
17-
ThrowError -ExceptionName 'System.ArgumentException' `
18-
-ExceptionMessage ($LocalizedData.PackageSourceNotFound -f ($Request.Source)) `
19-
-ErrorId 'PackageSourceNotFound' `
20-
-ErrorCategory InvalidArgument `
21-
-ExceptionObject $Request.Source
17+
throw 'The specified source is not registered with the package provider.'
2218
}
2319
} else {
2420
# User did not specify a source. Now what?
@@ -30,10 +26,7 @@ function Find-ChocoPackage {
3026
$DefaultPackageSource
3127
} else {
3228
# If the default assumed source is not present and no source specified, we can't guess what the user wants - throw an exception
33-
ThrowError -ExceptionName 'System.ArgumentException' `
34-
-ExceptionMessage $LocalizedData.UnspecifiedSource `
35-
-ErrorId 'UnspecifiedSource' `
36-
-ErrorCategory InvalidArgument
29+
throw 'Multiple non-default sources are defined, but no source was specified. Source could not be determined.'
3730
}
3831
}
3932
)

src/private/Get-ChocoPackage.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ function Get-ChocoPackage {
1919
# Filter results by any name and version requirements
2020
# We apply additional package name filtering when using wildcards to make Chocolatey's wildcard behavior more PowerShell-esque
2121
Foil\Get-ChocoPackage @chocoParams |
22-
Where-Object {-Not $Request.Name -Or ($Request.IsMatch($_.Name))} |
22+
Where-Object {$Request.IsMatch($_.Name)} |
2323
Where-Object {-Not $Request.Version -Or (([NuGet.Versioning.VersionRange]$Request.Version).Satisfies($_.Version))}
2424
}

test/AnyPackage.Chocolatey.Unit.Tests.ps1

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Describe 'version filters' {
144144
}
145145
}
146146

147-
Describe "error handling on Chocolatey failures" {
147+
Describe "error handling" {
148148
Context 'package installation' {
149149
BeforeAll {
150150
$package = 'googlechrome'
@@ -172,4 +172,35 @@ Describe "error handling on Chocolatey failures" {
172172
{Uninstall-Package -Name $package -ErrorAction Stop -WarningAction SilentlyContinue} | Should -Throw
173173
}
174174
}
175+
176+
Context 'ambiguous sources' {
177+
BeforeAll {
178+
$package = 'cpu-z'
179+
$defaultSource = 'chocolatey'
180+
$chocoSource = Get-PackageSource -name $defaultSource | Select-Object -ExpandProperty Location
181+
Get-PackageSource | Unregister-PackageSource
182+
@('test1','test2') | Register-PackageSource -Location $chocoSource -Provider Chocolatey
183+
}
184+
185+
It 'refuses to find packages when the specified source does not exist' {
186+
{Find-Package -Name $package -Source $defaultSource -ErrorAction Stop} | Should -Throw 'The specified source is not registered with the package provider.'
187+
}
188+
189+
It 'refuses to install packages when the specified source does not exist' {
190+
{Install-Package -Name $package -Source $defaultSource -ErrorAction Stop} | Should -Throw 'The specified source is not registered with the package provider.'
191+
}
192+
193+
It 'refuses to find packages when multiple custom sources are defined and no source specified' {
194+
{Find-Package -Name $package -ErrorAction Stop} | Should -Throw 'Multiple non-default sources are defined, but no source was specified. Source could not be determined.'
195+
}
196+
197+
It 'refuses to install packages when multiple custom sources are defined and no source specified' {
198+
{Install-Package -Name $package -ErrorAction Stop} | Should -Throw 'Multiple non-default sources are defined, but no source was specified. Source could not be determined.'
199+
}
200+
201+
AfterAll {
202+
Get-PackageSource | Unregister-PackageSource
203+
Register-PackageSource -Name $defaultSource -Location $chocoSource -Provider Chocolatey
204+
}
205+
}
175206
}

0 commit comments

Comments
 (0)