ethanbergstrom / Chocolatier

Package Management (OneGet) provider that facilitates installing Chocolatey packages from any NuGet repository.
MIT License
14 stars 2 forks source link

Find-Package needs some error handling #6

Closed raandree closed 4 years ago

raandree commented 4 years ago

Find-Package did not work. As one can't specify the source, it is unclear where the cmdlet goes to.

PS C:\> Find-Package -Name putty
You cannot call a method on a null-valued expression.
At C:\Program Files\WindowsPowerShell\Modules\Chocolatier\1.0.4\src\private\Find-ChocoPackage.ps1:18 char:2
+     Confirm-VersionParameters -Name $Name -MinimumVersion $MinimumVer ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\Program Files\WindowsPowerShell\Modules\Chocolatier\1.0.4\src\private\MiscHelpers.ps1:11 char:5
+     if($options.ContainsKey($script:additionalArguments)) {
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\Program Files\WindowsPowerShell\Modules\Chocolatier\1.0.4\src\private\MiscHelpers.ps1:28 char:6
+     if ($options.ContainsKey('Force')) {
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\Program Files\WindowsPowerShell\Modules\Chocolatier\1.0.4\src\private\Find-ChocoPackage.ps1:67 char:12
+ ...   } elseif ($minimumVersion -or $maximumVersion -or $options.Contains ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\Program Files\WindowsPowerShell\Modules\Chocolatier\1.0.4\src\private\MiscHelpers.ps1:11 char:5
+     if($options.ContainsKey($script:additionalArguments)) {
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\Program Files\WindowsPowerShell\Modules\Chocolatier\1.0.4\src\private\MiscHelpers.ps1:28 char:6
+     if ($options.ContainsKey('Force')) {
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

New-SoftwareIdentity : The term 'New-SoftwareIdentity' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, 
verify that the path is correct and try again.
At C:\Program Files\WindowsPowerShell\Modules\Chocolatier\1.0.4\src\private\ConvertTo-SoftwareIdentity.ps1:42 char:6
+                     New-SoftwareIdentity @swid
+                     ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (New-SoftwareIdentity:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
ethanbergstrom commented 4 years ago

Hey @raandree

How did you import the provider? Did you run Import-Module Chocolatier or Import-PackageProvider Chocolatier?

If I run Import-Module I get the output you're seeing, but the provider should be imported using Import-PackageProvider or by explicitly specifying the provider name in the PackageManagement cmdlet.

For example:

Import-PackageProvider Chocolatier
Find-Package -Name Putty
# or
Find-Package -Name Putty -ProviderName Chocolatier

Please see https://github.com/ethanbergstrom/Chocolatier#install-chocolatier and https://github.com/ethanbergstrom/Chocolatier#search-for-a-package for additional examples, and let me know if you have any additional questions.

raandree commented 4 years ago

Do you use the Find-Package function provided by the Chocolatier module or is this for internal use only?

ethanbergstrom commented 4 years ago

The Find-Package cmdlet called by users directly should be provided by the PackageManagement module, not the underlying provider module.

Provider modules should not be imported directly into the PowerShell session.

With a fresh PowerShell session, please use Import-PackageProvider Chocolatier, not Import-Module Chocolatier.

Please see https://docs.microsoft.com/en-us/powershell/module/packagemanagement/Import-PackageProvider for more information.

raandree commented 4 years ago

Thanks, this is then almost a duplicate to #5.