ScoopInstaller / Scoop

A command-line installer for Windows.
https://scoop.sh
Other
21k stars 1.4k forks source link

[Bug] Cannot bind argument to parameter 'AppName' because it is an empty string. #4916

Closed ocitrev closed 2 years ago

ocitrev commented 2 years ago

Bug Report

Current Behavior

The command scoop update * displays the following error message:

Select-CurrentVersion: C:\Users\ebouchard\scoop\apps\scoop\current\lib\core.ps1:222
Line |
 222 |      return $null -ne (Select-CurrentVersion -AppName $app -Global:$gl …
     |                                                       ~~~~
     | Cannot bind argument to parameter 'AppName' because it is an empty string.

Expected Behavior

No error message should be displayed when running command scoop update *

Additional context/output

This error does not seem to affect the actual update process

Possible Solution

System details

Windows version: 11

OS architecture: 64-bit

PowerShell version:

Name                           Value
----                           -----
PSVersion                      7.2.3
PSEdition                      Core
GitCommitId                    7.2.3
OS                             Microsoft Windows 10.0.22000
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Additional software: Windows Terminal

Scoop Configuration

{
  "lastupdate": "2022-05-10T14:38:57.9590016-04:00",
  "SCOOP_REPO": "https://github.com/lukesampson/scoop",
  "SCOOP_BRANCH": "master"
}
rashil2000 commented 2 years ago

scoop list?

ocitrev commented 2 years ago

Nope, only scoop update * scoop update does not show this error message either.

PS> scoop list
Installed apps:

Name          Version          Source                                                        Updated             Info
----          -------          ------                                                        -------             ----
7zip          21.07            main                                                          2022-01-10 08:01:32
azure-cli     2.36.0           main                                                          2022-05-05 09:05:06
bat           0.20.0           main                                                          2022-04-12 22:04:21
cacert        2022-04-26       main                                                          2022-05-05 09:05:06
cloc          1.92             main                                                          2021-12-14 16:12:55
cmake         3.23.1           main                                                          2022-04-21 11:04:41
cppcheck      2.7              main                                                          2022-02-16 00:02:35
ctags         5.8              main                                                          2020-03-25 13:03:06
dark          3.11.2           main                                                          2020-04-22 09:04:22
docker        20.10.15         main                                                          2022-05-10 14:05:47
dog           0.1.0            main                                                          2022-04-12 22:04:10
dust          0.8.0            main                                                          2022-04-12 22:04:01
everything    1.4.1.1015       extras                                                        2021-12-22 00:12:13
ffmpeg        5.0.1            main                                                          2022-04-21 11:04:51
Filezilla     3.59.0           extras                                                        2022-04-21 11:04:55
fx            24.0.0           main                                                          2022-05-10 14:05:48
fzf           0.30.0           main                                                          2022-04-21 11:04:56
gcc           11.2.0           main                                                          2021-12-14 16:12:26
git           2.36.1.windows.1 main                                                          2022-05-10 14:05:59
go            1.18.2           main                                                          2022-05-10 16:05:18
heroku-cli    7.60.2           main                                                          2022-05-05 09:05:29
hexchat       2.16.1           extras                                                        2022-02-16 00:02:19
ilspy         7.2.1.6856       extras                                                        2022-04-21 11:04:54
innounp       0.50             main                                                          2021-01-03 21:01:36
iperf3        3.1.3            main                                                          2021-01-28 20:01:27
lessmsi       1.10.0           main                                                          2021-11-30 16:11:09
LicenseInfo   1.0.1            C:\Travail\InternalTools\LicenseInfo\publish\LicenseInfo.json 2021-06-02 11:06:28
llvm          14.0.3           main                                                          2022-05-05 09:05:48
mosh-client   1.3.2            main                                                          2022-04-12 22:04:29
mp3tag        3.14             extras                                                        2022-04-21 11:04:15
msys2         2022-05-03       main                                                          2022-05-05 09:05:20
nano          6.3-7            main                                                          2022-05-05 09:05:22
neovim        0.7.0            main                                                          2022-04-21 11:04:47
ngrok         2.3.40           main                                                          2021-05-07 23:05:26
ninja         1.10.2           main                                                          2020-11-28 10:11:22
nodejs        18.1.0           main                                                          2022-05-05 09:05:27
nodejs-lts    16.15.0          main                                                          2022-05-05 09:05:32
nomacs        3.16.1709        extras                                                        2021-10-04 22:10:14
nuget         6.1.0            main                                                          2022-04-21 11:04:58
optipng       0.7.7            main                                                          2021-12-23 10:12:50
perl          5.32.1.1         main                                                          2021-05-25 13:05:03
picotorrent   0.25.0           extras                                                        2021-05-20 08:05:01
putty         0.76             extras                                                        2021-07-26 14:07:25
rawtherapee   5.8              extras                                                        2021-10-04 22:10:15
ruby          3.1.2-1          main                                                          2022-04-21 11:04:28
rustup        1.24.3           main                                                          2021-06-10 11:06:31
s             0.6.6            main                                                          2022-03-15 10:03:12
scc           3.0.0            main                                                          2021-05-27 16:05:40
sharpkeys     3.9.4            extras                                                        2022-04-21 11:04:28
tightvnc      2.8.63           extras                                                        2021-10-04 22:10:51
uncap         0.3.0            main                                                          2020-10-14 23:10:01
vlc           3.0.17.4         extras                                                        2022-04-21 11:04:33
vncviewer     6.22.315         extras                                                        2022-04-21 11:04:35
wget          1.21.3           main                                                          2022-03-15 10:03:15
xh            0.16.0           main                                                          2022-04-21 11:04:36
youtube-dl    2021.12.17       main                                                          2021-12-22 00:12:31
dosbox        0.74-3           main                                                          2021-05-25 12:05:08 Global install
win32-openssh 8.6.0.0p1-Beta   main                                                          2021-06-14 09:06:33 Global install

PS> scoop update
Updating Scoop...
Updating 'extras' bucket...
Updating 'main' bucket...
Scoop was updated successfully!

PS> scoop update *
Select-CurrentVersion: C:\Users\ebouchard\scoop\apps\scoop\current\lib\core.ps1:222
Line |
 222 |      return $null -ne (Select-CurrentVersion -AppName $app -Global:$gl …
     |                                                       ~~~~
     | Cannot bind argument to parameter 'AppName' because it is an empty string.

Latest versions for all apps are installed! For more information try 'scoop status'
lewis-yeung commented 2 years ago

Cannot repro this in PowerShell v7.2.3 on my end.

ocitrev commented 2 years ago

After a bit of digging it is my local json package that is causing this.

I believe the source of this issue is in function app_status core.ps1:358

$deps = @($manifest.depends) | Where-Object {
    if ($null -eq $_) { # <-- this is false because $_ is empty string
        return $null
    } else {
        $app, $bucket, $null = parse_app $_
        return !(installed $app)  # <-- installed gets called with empty string and complains
    }
}

Replacing the null check with [string]::IsNullOrEmpty($_) seems to "fix" the issue.

I am hesitant to create a pull request with this fix. I am not familiar with this code base, I cannot tell if this is a good fix or not. Perhaps there is another underlying issue ?

ocitrev commented 2 years ago

My change to silence the error

index 83e7a28a..16b482e9 100644
--- a/lib/core.ps1
+++ b/lib/core.ps1
@@ -356,7 +356,7 @@ function app_status($app, $global) {

     $status.missing_deps = @()
     $deps = @($manifest.depends) | Where-Object {
-        if ($null -eq $_) {
+        if ([string]::IsNullOrEmpty($_)) {
             return $null
         } else {
             $app, $bucket, $null = parse_app $_
rashil2000 commented 2 years ago

Can you paste the problematic manifest json here?

ocitrev commented 2 years ago

Sure !

{
  "extract_dir": "",
  "license": "",
  "bin": "LicenseInfo.exe",
  "homepage": "",
  "url": "C:\\Travail\\InternalTools\\LicenseInfo\\publish\\LicenseInfo.7z",
  "version": "1.0.1",
  "hash": "ee00df5afd4bb31fc42d11b8f7e63d7b2d97cc64958be481351c2670b388697f",
  "depends": ""
}
ocitrev commented 2 years ago

Removing the depends field in the json does also silence the error message.

ocitrev commented 2 years ago

I remember using the scoop create command to create the json file. I just tried the command again and it creates an empty string depends field.

ocitrev commented 2 years ago
PS> scoop create https://github.com/ScoopInstaller/Scoop/issues/4916
1) ScoopInstaller
2) Scoop
3) issues
4) 4916
App name: 2
1) ScoopInstaller
2) Scoop
3) issues
4) 4916
Version: 4
Created 'C:\Users\ebouchard\Scoop.json'.

PS> cat C:\Users\ebouchard\Scoop.json
{
  "version": "4916",
  "url": "https://github.com/ScoopInstaller/Scoop/issues/4916",
  "license": "",
  "extract_dir": "",
  "bin": "",
  "homepage": "",
  "hash": "",
  "depends": ""
}
rashil2000 commented 2 years ago

Oh, you're supposed to fill those fields, or remove them if not needed 😅

Empty/blank fields in the JSON are not allowed.

ocitrev commented 2 years ago

you're supposed to fill those fields, or remove them if not needed

Thanks ! I wish a json comment saying this sentence was generated by scoop create