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

Parse Error in PS5 #135

Open
dan-hughes opened this issue Feb 16, 2025 · 2 comments
Open

Parse Error in PS5 #135

dan-hughes opened this issue Feb 16, 2025 · 2 comments

Comments

@dan-hughes
Copy link

Module does not load in PowerShell 5.1, it seems to be unhappy with the below.

Version = if (($V = $BuildInfo.SemVer.Split("+")[0].Split("-", 2)[0])) {
[version]$V
}

Run Import-Module in PS5 to reproduce. PS7 is fine.

@johlju
Copy link
Contributor

johlju commented Feb 17, 2025

I think I got the same error, it starts failing on line 505 in ModuleBuilder which is the line 42 in the above snippet from InitializeBuild.ps1.

It happens in integration tests in Sampler module pipeline that is using PS5.1, integration tests for PS7.x works.

The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: At D:\a\1\s\output\RequiredModules\ModuleBuilder\3.1.6\ModuleBuilder.psm1:505 char:30
##[error]     +                             }
##[error]     +                              ~
##[error]     The hash literal was incomplete.
##[error]     At D:\a\1\s\output\RequiredModules\ModuleBuilder\3.1.6\ModuleBuilder.psm1:509 char:34
##[error]     +     } elseif($BuildInfo.Version) {
##[error]     +                                  ~
##[error]     Unexpected token '{' in expression or statement.
##[error]     At D:\a\1\s\output\RequiredModules\ModuleBuilder\3.1.6\ModuleBuilder.psm1:533 char:1
##[error]     + }
##[error]     + ~

@grey0ut
Copy link

grey0ut commented Mar 6, 2025

I just installed the module in 5.1 and encounter the same error for psm1:505 as well.
As a test I tried wrapping the value definition in a subexpression and the module loaded.
Using this code as a test:

@{
    Key1 = "Somevalue"
    Key2 = if ($R = 2/2) {
        [Boolean]$R
    }
    Key3 = "SomeOtherValue"
}

When executing it in Windows Powershell 5.1 it errors that the hashliteral is incomplete.
When executing it in Pwsh 7.5.0 it completes and outputs successfully.
Changing the code to use a subexpression like this works in both versions:

@{
    Key1 = "Somevalue"
    Key2 = $(if ($R = 2/2) {
        [Boolean]$R
    })
    Key3 = "SomeOtherValue"
}

Oh, now I see that #136 fixes this by changing the order of the definition. That works too it seems.

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

3 participants