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

Windows install script error #109

Open
zoete opened this issue Feb 21, 2025 · 3 comments
Open

Windows install script error #109

zoete opened this issue Feb 21, 2025 · 3 comments

Comments

@zoete
Copy link

zoete commented Feb 21, 2025

Hey, yek worked great on my Mac, so I also wanted to put it on my Win11 system, I ran into this small issue:

Line 69 in yek.ps1 should be:

$binaryPath = "$extractDir\yek-$target\yek.exe"

Instead of:

$binaryPath = Join-Path $extractDir "yek-$target" "yek.exe"

On a fresh Win 11 install I got:

Moving binary to C:\Users\Z\.local\bin...
Join-Path : A positional parameter cannot be found that accepts argument 'yek.exe'.
At C:\Users\Z\yek.ps1:69 char:15
+ $binaryPath = Join-Path $extractDir "yek-$target" "yek.exe"
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Join-Path], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.JoinPathCommand

After the adjustment the install went through without issues. You might also want to specify users should run Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process to be able to run the script.

Copy link

codeautopilot bot commented Feb 21, 2025

Potential solution

The plan to solve the bug involves addressing the path construction issue in the PowerShell script and providing guidance on setting the execution policy. The error arises because the Join-Path command is not correctly handling multiple arguments in the given context. By switching to direct string interpolation for path construction, we can ensure the path is correctly formed. Additionally, informing users about setting the execution policy will prevent permission-related errors when running the script.

What is causing this bug?

The bug is caused by the incorrect usage of the Join-Path command in the PowerShell script. The command is not handling multiple arguments as expected, leading to an error when constructing the path for the yek.exe binary. The error message indicates that a positional parameter cannot be found for the argument 'yek.exe', which suggests that Join-Path is not concatenating the path segments correctly. This issue can be resolved by using direct string interpolation to construct the path.

Code

Here are the implementation details and code snippets to fix the bug:

  1. Fix Path Construction: Replace the Join-Path command with direct string interpolation to construct the path:

    $binaryPath = "$extractDir\yek-$target\yek.exe"
  2. Add Execution Policy Instructions: Include instructions at the beginning of the script to inform users about setting the execution policy:

    Write-Host "If you encounter execution policy errors, run the following command:"
    Write-Host "Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process"

How to replicate the bug

To replicate the bug, follow these steps:

  1. Set up a fresh Windows 11 installation.
  2. Attempt to run the install_yek.ps1 script without modifying it.
  3. Observe the error message indicating a problem with the Join-Path command:
    Join-Path : A positional parameter cannot be found that accepts argument 'yek.exe'.
    

By following these steps, you should encounter the same error as reported in the ticket.

By implementing the suggested fixes, the script should run without issues, and users will be informed about setting the execution policy to avoid permission-related errors.

Click here to create a Pull Request with the proposed solution

Files used for this task:

Changes on scripts/install_yek.ps1

Analysis

The issue reported by the user is related to the construction of the file path using the Join-Path command in the PowerShell script. The error message indicates that Join-Path is not handling the arguments as expected, leading to a failure in constructing the correct path for the yek.exe binary.

Identified Problems

  1. Path Construction Issue: The line causing the issue is:

    $binaryPath = Join-Path $extractDir "yek-$target" "yek.exe"

    The Join-Path command is not correctly handling multiple arguments in this context, which leads to the error: "A positional parameter cannot be found that accepts argument 'yek.exe'."

  2. Execution Policy: The user also mentioned needing to set the execution policy to bypass restrictions, which is a common requirement for running scripts on Windows but is not mentioned in the script.

Suggested Fixes

  1. Fix Path Construction: Replace the Join-Path command with a direct string interpolation method to construct the path:

    $binaryPath = "$extractDir\yek-$target\yek.exe"
  2. Add Execution Policy Instructions: Include instructions at the beginning of the script to inform users about setting the execution policy:

    Write-Host "If you encounter execution policy errors, run the following command:"
    Write-Host "Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process"

Conclusion

The script should be updated to fix the path construction issue by using direct string interpolation instead of Join-Path. Additionally, adding a note about setting the execution policy will help users run the script without encountering permission issues. These changes should resolve the reported bug and improve the user experience.

This comment was generated by AI. Information provided may be incorrect.

Current plan usage: 53%

Have feedback or need help?
Documentation
[email protected]

@mohsen1
Copy link
Collaborator

mohsen1 commented Feb 22, 2025

Thank you for reporting the bus. I wonder why this is not failing in my post publish script here.

https://github.com/bodo-run/yek/blob/main/.github/workflows/test-install.yml

Since I don't have a Windows machine, I can't really test this out. Would you be able to help me with debugging this?

@zoete
Copy link
Author

zoete commented Feb 25, 2025

Happy to help, my theory would be that GHA windows-latest is optimized to not have too much friction.

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

No branches or pull requests

2 participants