Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] strip_path's parameter is not correctly passed to Split-PathLikeEnvVar #5936

Closed
Capella87 opened this issue May 2, 2024 · 2 comments · Fixed by #5964
Closed

[Bug] strip_path's parameter is not correctly passed to Split-PathLikeEnvVar #5936

Capella87 opened this issue May 2, 2024 · 2 comments · Fixed by #5964
Labels

Comments

@Capella87
Copy link
Contributor

Bug Report

Current Behavior

One parameter was entered with a different name, so the following error occurs every time it is installed or uninstalled.

InvalidOperation: C:\Users\[redacted]\scoop\apps\scoop\current\lib\system.ps1:85
Line |
  85 |          $splitPattern = $Pattern.Split(';', [System.StringSplitOption|          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.

Since $Pattern is $null, it occurs error.

Expected Behavior

In sdl2 manifest, strip_path function has been invoked several times. For example, in the manifest's installer script:

"$null, $currpath = strip_path (env 'PKG_CONFIG_PATH' $global) $pcdir",
"env 'PKG_CONFIG_PATH' $global \"$pcdir;$currpath\"",

strip_path function requires two parameters, the returned variable from env and $pcdir respectively. And it utilizes the second returned one, $currpath and makes use of it to configure paths.
Since the function is a deprecated function, it actually outputs a warning and then another function, Split-PathLikeEnvVar is called. In the past, it was Test-PathLikeEnvVar and required two string variables, $Name and '$Path'.

In the recent commit, The string type $Name parameter has been updated to the string array type $Pattern. But strip_path still provides the parameter with the old name.
So, Split-PathLikeEnvVar wants $Pattern, but it has $null value, then the error occurs.

Additional context/output

I discovered this issue at sdl2 manifest which contains the problematic functions stored at ScoopInstaller/Extras. Here's the output:

PS> scoop update sdl2
Uninstalling 'sdl2' (2.30.2)
Running uninstaller script...
WARN  "env" will be deprecated. Please change your code/manifest to use "Get-EnvVar"
      -> :4:38
WARN  "strip_path" will be deprecated. Please change your code/manifest to use "Split-PathLikeEnvVar"
      -> :4:26
InvalidOperation: C:\Users\[redacted]\scoop\apps\scoop\current\lib\system.ps1:85
Line |
  85 |          $splitPattern = $Pattern.Split(';', [System.StringSplitOption|          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.
WARN  "env" will be deprecated. Please change your code/manifest to use "Get-EnvVar"
      -> :9:38
WARN  "strip_path" will be deprecated. Please change your code/manifest to use "Split-PathLikeEnvVar"
      -> :9:26
InvalidOperation: C:\Users\[redacted]\scoop\apps\scoop\current\lib\system.ps1:85
Line |
  85 |          $splitPattern = $Pattern.Split(';', [System.StringSplitOption|          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.
WARN  "strip_path" will be deprecated. Please change your code/manifest to use "Split-PathLikeEnvVar"
      -> :15:26
InvalidOperation: C:\Users\[redacted]\scoop\apps\scoop\current\lib\system.ps1:85
Line |
  85 |          $splitPattern = $Pattern.Split(';', [System.StringSplitOption|          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.
WARN  "strip_path" will be deprecated. Please change your code/manifest to use "Split-PathLikeEnvVar"
      -> :17:26
InvalidOperation: C:\Users\[redacted]\scoop\apps\scoop\current\lib\system.ps1:85
Line |
  85 |          $splitPattern = $Pattern.Split(';', [System.StringSplitOption|          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.
Unlinking ~\scoop\apps\sdl2\current
Installing 'sdl2' (2.30.3) [64bit] from 'extras' bucket
Loading SDL2-devel-2.30.3-VC.zip from cache.
Loading SDL2-2.30.3.zip from cache.
Extracting SDL2-devel-2.30.3-VC.zip ... done.
Extracting SDL2-2.30.3.zip ... done.
Running installer script...
WARN  "env" will be deprecated. Please change your code/manifest to use "Get-EnvVar"
      -> :33:32
WARN  "strip_path" will be deprecated. Please change your code/manifest to use "Split-PathLikeEnvVar"
      -> :33:20
InvalidOperation: C:\Users\[redacted]\scoop\apps\scoop\current\lib\system.ps1:85
Line |
  85 |          $splitPattern = $Pattern.Split(';', [System.StringSplitOption|          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.
WARN  "env" will be deprecated. Please change your code/manifest to use "Set-EnvVar"
      -> :34:1
WARN  "env" will be deprecated. Please change your code/manifest to use "Get-EnvVar"
      -> :35:32
WARN  "strip_path" will be deprecated. Please change your code/manifest to use "Split-PathLikeEnvVar"
      -> :35:20
InvalidOperation: C:\Users\[redacted]\scoop\apps\scoop\current\lib\system.ps1:85
Line |
  85 |          $splitPattern = $Pattern.Split(';', [System.StringSplitOption|          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.
WARN  "env" will be deprecated. Please change your code/manifest to use "Set-EnvVar"
      -> :36:1
WARN  "strip_path" will be deprecated. Please change your code/manifest to use "Split-PathLikeEnvVar"
      -> :38:31
InvalidOperation: C:\Users\[redacted]\scoop\apps\scoop\current\lib\system.ps1:85
Line |
  85 |          $splitPattern = $Pattern.Split(';', [System.StringSplitOption|          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.
WARN  "strip_path" will be deprecated. Please change your code/manifest to use "Split-PathLikeEnvVar"
      -> :40:33
InvalidOperation: C:\Users\[redacted]\scoop\apps\scoop\current\lib\system.ps1:85
Line |
  85 |          $splitPattern = $Pattern.Split(';', [System.StringSplitOption|          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.
Linking ~\scoop\apps\sdl2\current => ~\scoop\apps\sdl2\2.30.3
'sdl2' (2.30.3) was installed successfully!

Possible Solution

This problem can be resolved with 2 ways. We should update strip_path function in lib/system.ps1 to provide the parameter with -Pattern. Also, Split-PathLikeEnvVar now receives the changed one as a string array, it would be better to include casting to array before invoking the function.

strip_path is a deprecated function, so manifests that uses it should be updated not to use that function.

System details

Windows version: Windows 10 22H2, and Windows 11 23H2 (Tested on both environments)

OS architecture: AMD64 (x64)

PowerShell version: [output of "$($PSVersionTable.PSVersion)"]

PS> $PSVersionTable

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

Additional software:
None

Scoop Configuration

{
  "last_update": "2024-05-02T11:52:06.2956348+09:00",
  "debug": true,
  "aria2-enabled": true,
  "aria2-warning-enabled": false,
  "use_external_7zip": true,
  "scoop_branch": "master",
  "scoop_repo": "https://github.com/ScoopInstaller/Scoop"
}
@william-lohan
Copy link

I'm running into this issue installing both sdl2 and raylib-mingw. Any work around?

@Capella87
Copy link
Contributor Author

@william-lohan I checked that this issue is from installer script, which contains legacy functions including strip_path. This trouble is appeared after updating Scoop to v0.4.x recently, and we could solve this problem by replacing legacy functions in script with newer functions. I will make pull requests for those manifests regarding this issue to Scoop's repositories as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants