Skip to content

fix: resolve PowerShell 5.1 syntax error and add version checks#5

Closed
jlaportebot wants to merge 2 commits into
aweussom:mainfrom
jlaportebot:fix/powershell-version-checks
Closed

fix: resolve PowerShell 5.1 syntax error and add version checks#5
jlaportebot wants to merge 2 commits into
aweussom:mainfrom
jlaportebot:fix/powershell-version-checks

Conversation

@jlaportebot
Copy link
Copy Markdown

Summary

This PR fixes the PowerShell 5.1 syntax error reported in issue #3 and adds comprehensive version checking to prevent similar issues.

Changes

Bug Fix

  • Fixed missing closing brace in install.ps1 that caused syntax error in PowerShell 5.1
  • The error occurred at line 291 where the main if ($HasNPU) block was not properly closed before the elseif statement

Improvements

  • Added PowerShell version check at script startup
  • Warns users running PowerShell < 7 about potential compatibility issues
  • Provides clear upgrade instructions with link to PowerShell 7 download
  • Allows users to continue with older versions after explicit confirmation
  • Added Python availability check before installation
  • Displays Python version for verification
  • Provides clear error messages when Python is not found

Testing

  • Verified brace count is balanced (84 open, 84 close)
  • Script structure is now syntactically correct for all PowerShell versions
  • Version checks provide helpful guidance to users
  • Error messages are clear and actionable

Impact

Users running PowerShell 5.1 will now:

  1. See a clear warning about version compatibility
  2. Get instructions to upgrade to PowerShell 7
  3. Have the option to continue after acknowledging the warning
  4. No longer encounter cryptic syntax errors

Fixes #3

- Fix missing closing brace causing syntax error in PowerShell 5.1
- Add PowerShell version check with warning for versions < 7
- Add Python availability check before installation
- Provide clear error messages and upgrade instructions
- Allow users to continue with older PowerShell versions after warning

Fixes aweussom#3
@aweussom
Copy link
Copy Markdown
Owner

Thanks for the work on this, @jlaportebot, and for putting the careful description together.

I went with a smaller fix on main instead: #requires -Version 7.0 at line 1 of install.ps1 (see commit 7139304). On PS 5.1 it now exits cleanly with ScriptRequiresUnmatchedPSVersion before full tokenization, plus a one-line note in README's Requirements that PS 7+ is required.

One detail worth flagging for posterity: the MissingEndCurlyBrace at line 291 from issue #3 isn't actually a brace bug. install.ps1 is stored as UTF-8 without BOM, so Windows PowerShell 5.1 reads it via the system code page (Windows-1252 on most installs). The UTF-8 em-dash bytes (E2 80 94) in string literals further down (lines 380-382) get mis-decoded, breaking tokenization inside the string, and the parser eventually fails at the next opening { it can't match. The "brace" line is a downstream symptom of the encoding issue, not a real brace mismatch. #requires heads it off because PowerShell validates that directive before fully tokenizing the file.

Closing the PR since the concern is addressed on main, but appreciate you putting the time in — the surface area would have been larger here than the alternative warranted, and the encoding angle wouldn't have come out without your investigation. Thanks again.

@aweussom aweussom closed this May 25, 2026
@jlaportebot
Copy link
Copy Markdown
Author

Thanks for the thorough explanation, @aweussom! The #requires -Version 7.0 approach is elegant — much cleaner than the broader fix I proposed. Really interesting detail about the UTF-8 BOM / Windows-1252 encoding being the root cause of the MissingEndCurlyBrace error. Appreciate you taking the time to explain that, and glad the investigation was useful!

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

Successfully merging this pull request may close these issues.

Syntax error in default powershell 5.1

2 participants