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

Yamlcreate.ps1 throws exception: "Join-Path : A positional parameter cannot be found that accepts argument" #3061

Closed
philnach opened this issue Aug 12, 2020 · 9 comments · Fixed by #3241
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation.
Milestone

Comments

@philnach
Copy link
Member

Brief description of your issue

Ran the YamlCreate.ps1 script from directly from the tools directory results in invalid argument exception when the tool goes to build manifest due to a package id folder not existing

Steps to reproduce

Run YamlCreate.ps1 directly from the tools directory. Below are the specified values I entered:

Id: skylot.jadx
Version: 1.1.0
Name: jadx
Publisher: skylot
License: Apache License 2.0
LicenseUrl: https://github.com/skylot/jadx/blob/master/LICENSE
AppMoniker: jadx
Tags: Java, Dex, android, APK
Description: Command line and GUI tools to produce Java source code from Android Dex and APK files
Homepage: https://github.com/skylot/jadx
Arch: Neutral
Url: https://github.com/skylot/jadx/releases/download/v1.1.0/jadx-gui-1.1.0-no-jre.exe
Sha256: D2D8FBB71BAEC7FFE99633231397DFF419AB12D09C18171E75DAE6D994C79984
InstallerType: exe

Expected behavior

YamlCreate.ps1 doesn't throw an exception and creates manifest in a package id folder

Actual behavior

Exception is thrown during script execution:

Join-Path : A positional parameter cannot be found that accepts argument 'System.Object[]'.
At C:\repos\winget-pkgs\Tools\YamlCreate.ps1:247 char:21
+     $FileLocation = Join-Path "\" "manifests" $id.Split('.')[0..1]
+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Join-Path], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.JoinPathCommand

Environment

Windows 10 2004 OS Build 19041.450

[winget --info]
Windows: Windows.Desktop v10.0.19041.450
Package: Microsoft.DesktopAppInstaller v1.10.42101.0
@ghost ghost added the Needs: Triage label Aug 12, 2020
@perplexityjeff
Copy link
Contributor

perplexityjeff commented Aug 13, 2020

I have tried to reproduce the issue but I am unable to get the same error. I did however use PowerShell Core 7. I did use x86 as the arch but that should not matter?

testjadx

image

I added Jadx 1.1.0 in a new pull request here #3066

EDIT: I did some more testing on what and how Jadx's behavior is and found out that it does not have an installer. It is a portable application that does not require installation so it is not very manageable with winget. Possible issue to support this microsoft/winget-cli#182

@denelon
Copy link
Contributor

denelon commented Aug 13, 2020

@philnach are you able to reproduce the issue?
If so, which version of PowerShell/Terminal are you using?

@denelon denelon added Issue-Bug It either shouldn't be doing this or needs an investigation. Needs: author feedback and removed Needs: Triage labels Aug 13, 2020
@philnach
Copy link
Member Author

@denelon, I'll attach the PowerShell execution transcript for you later today.

@philnach
Copy link
Member Author

@denelon , I tried with x86 as well, still the same failure. Attached is the PowerShell transcript
YamlCreateTranscript.log

@philnach
Copy link
Member Author

philnach commented Aug 14, 2020

@denelon, I think I figured it out.

I'm on PowerShell 5.1 and in PowerShell 6.0 "-AdditionalChildPath" was added which let's you append multiple paths together StackOverflow suggestion.

We could fix the line by doing the following:

$FileLocation = Join-Path "" -ChildPath "manifests" | Join-Path -ChildPath $id.Split('.')[0] | Join-Path -ChildPath $id.Split('.')[1]

I'm more than happy to create a PR, unless you think we should require a minimum of PowerShell 6 for running the script?

@denelon
Copy link
Contributor

denelon commented Aug 17, 2020

@philnach as long as this isn't going to be a breaking change for other versions of PowerShell, I'm fine with supporting multiple earlier versions.

@philnach
Copy link
Member Author

@denelon, perfect, I'll get the change coded up and verify PowerShell 5.1, 6.0 and 7. Probably send out a PR tomorrow (8/21).

@megamorf
Copy link
Contributor

megamorf commented Aug 24, 2020

@philnach If you're going to submit a PR please don't submit a fix that looks like this

$FileLocation = Join-Path "" -ChildPath "manifests" | Join-Path -ChildPath $id.Split('.')[0] | Join-Path -ChildPath $id.Split('.')[1]

That code that is hard to maintain and does not follow PowerShell best practices. It probably makes sense to add a minimum version requirement to the script. This can be done by beginning the YamlCreate.ps1 script with the line:

#Requires -Version 5.1

You can then use PSScriptAnalyzer to tell you about incompatible version specific features.

Edit:
I can push a fix that makes the script PSv5 compatible again.

@philnach
Copy link
Member Author

@megamorf, thanks for the feedback, I'm not an expert when it comes to PowerShell, it would be awesome if you could fix the script to work with PowerShell 5.1? I had something slightly different, but it's good you brought up that it doesn't follow best practice.

megamorf pushed a commit to megamorf/winget-pkgs that referenced this issue Aug 25, 2020
* this commit removes PowerShell Core only features that were introduced with microsoft#2378 to ensure compatibility with PSv5
* adds comment based help
* use consistently cased Cmdlet and variable names
* improves input data related error handling
* adds PS code regions for automatic code folding
* automates the creation of the manifest file at the correct destination path
* corrects the use of Write-Host and Write-Output

Fixes microsoft#3061
KevinLaMS pushed a commit that referenced this issue Aug 27, 2020
* Make script PSv5 compatible again, apply some PS best practices

* this commit removes PowerShell Core only features that were introduced with #2378 to ensure compatibility with PSv5
* adds comment based help
* use consistently cased Cmdlet and variable names
* improves input data related error handling
* adds PS code regions for automatic code folding
* automates the creation of the manifest file at the correct destination path
* corrects the use of Write-Host and Write-Output

Fixes #3061

* Adhere to YAML formatting conventions

* Use cross-platform new line handling

Co-authored-by: Sebastian Neumann <sebastian.neumann@experienceone.com>
@denelon denelon added this to the 1.7 Packages milestone Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants