jdhitsolutions / WingetTools

A set of PowerShell tools for working with the winget package manager.
MIT License
157 stars 16 forks source link

[Bug]: When winget.exe fails to export package list to file, Get-WGInstalled returns an unrelated error message #16

Open bsudano opened 2 years ago

bsudano commented 2 years ago

Describe the problem

Running Get-WGInstalled -Verbose returns the following output:

VERBOSE: [14:14:23.7692236 BEGIN  ] Starting Get-WGInstalled
VERBOSE: [14:14:23.7695455] Starting Get-WGPath
VERBOSE: [14:14:23.7996964] Running as domain\ben
VERBOSE: [14:14:23.7999407] Using user default location
VERBOSE: [14:14:23.8001315] Ending Get-WGPath
VERBOSE: [14:14:23.8003343 PROCESS] Building list of packages with a winget source
WARNING: There was a problem getting a list of installed packages.
Get-Job: C:\Users\ben\Documents\PowerShell\Modules\WingetTools\1.6.0\functions\Get-WGInstalled.ps1:122
Line |
 122 |          if (Get-Job -Name wg) {
     |              ~~~~~~~~~~~~~~~~
     | The command cannot find the job because the job name wg was not found. Verify the value of the Name parameter, and then try the command again.

VERBOSE: [14:14:33.4908814 END    ] Ending Get-WGInstalled

Running & $winget export -s winget -o $tmpFile --include-versions directly produces the following error from winget.exe at the end of the output:

...
An unexpected error occurred while executing the command: 
Download request status is not success.
0x80190194 : Not found (404).

Expectation

Expectation was that if there were an internal winget.exe error, PowerShell's error stream would reflect that

Additional Information

I suppressed the Get-Job error by modifying line 122 in this way:

        if ('wg' -in (Get-Job).Name) {

But I am unsure of the best way to write useful error information from Winget to the PS error stream.

PowerShell version

7.2

Platform

Windows 10 Pro or Enterprise

Additional Checks

jdhitsolutions commented 2 years ago

winget doesn't behave like a typical command line tool, so this is indeed difficult. I'll see what I can do.