-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
Explicitly importing associated modules error message contains invalid syntax #3767
Comments
Surprisingly, it is going to like it. Unlike most other languages, PowerShell actually mostly recognizes (non-ASCII) Unicode whitespace and punctuation: Take the following command, for instance: Write-Host –NoNewline “$HOME” ‘literal’ With the exception of the hyphen in
I'm unclear on the exact rules and mapping, however. The above suggests that at least command names only work if you spell them exactly as defined (case differences aside). |
Well I guess I should have tested in it a regular console window, but it seems that the loose Unicode handling is a host-specific thing as this definitely did not work in a VSCode embeded powershell terminal. |
Actually, it does work in VSCode's PowerShell terminal, and it should work anywhere the Unicode encoding is preserved - but that perhaps points to the reason to better stick with ASCII: things may get lost in translation (transcoding)... |
@Cryowatt, could you please change the title to prevent confusion? It's not about invalid syntax, it's about unexpected use of (non-ASCII) Unicode punctuation. |
+1 for this. powershell didn't like it on my machine, in vscode. The failure condition is really weird too, with powershell complaining about unterminated quotes on the last line with double quotes in it. Fwiw, this sure looks like invalid syntax to my environment. |
That suggests that your file is UTF-8 without a BOM, which is a general problem you should address, because Windows PowerShell will misinterpret all non-ASCII-range characters in your file. With a properly encoded file, you can copy the command from the error message - That en-dashes also work in the integrated VS Code terminal can be verified by copying and pasting the following command, which should work: |
I had a working script and I pasted in literally what the error message told me to. Then I had a broken script. |
Indeed. Point being that PS itself should use errors that use the correct, unambiguous characters to avoid as many issues for the user as possible. Encoding is something that commonly has to be dealt with, but preferably we should avoid having to worry about encoding while handling what an error message has given us verbatim. |
It doesn't say that parameter names can start with whatever horizontal line you feel like at the time. |
Yeah. PS does attempt to parse other types of horizontal dash to make one's life easier, just like it tries to parse fancy quotes that MS Word and Outlook like to convert things into without asking. Unfortunately, with how encodings sometimes trip things up, it can't work 100% of the time. |
Agreed, @vexx32 - it's worth switching to a hyphen. That said, the error message isn't part of this repo, and it looks to me that the DSC code may not have been open-sourced (yet?), so the correct place to report this issue is https://windowsserver.uservoice.com/forums/301869-powershell?category_id=148047 Separately, it's important to understand the true issue here, and the true issue is one of character encoding. A lack of awareness of that can cause other problems down the line. @Cryowatt: Whether it's documented or not, PowerShell does support this substitution, as it does with other punctuation and quote characters, as @vexx32 mentions - see this Stack Overflow answer for details. @BenJTucker: While you may have no plans to use non-ASCII-range characters, know that saving your scripts as UTF-8 without BOM will cause Windows PowerShell to misinterpret them as ANSI-encoded, once you add a non-ASCII-range character - and as you've experienced, that can happen through copy and paste. The best cross-edition and cross-platform choice of encoding is UTF-8 with BOM. Lack of API support has so far prevented the PowerShell extension for VS Code from defaulting new PowerShell files to UTF-8 with BOM - see this issue, which also shows how you can manually configure VS Code that way. |
This issue has been marked as won't fix and has not had any activity for 1 day. It has been closed for housekeeping purposes. |
Steps to reproduce
Create a Powershell DSC configuration like this:
When you execute the configuration you'll end up with this error:
The given syntax isn't
-ModuleName
, it's–ModuleName
. Look closely, that's not a hyphen (0x2D), that's an en dash (0x2013). If you copy and paste that back into [some powershell hosts] it's not going to like it.Expected behavior
Hyphens
Actual behavior
En dashes
Environment data
The text was updated successfully, but these errors were encountered: