question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't paste a comment (`#`) after a pipe (`|`) and a newline

See original GitHub issue

Prerequisites

Steps to reproduce

Paste the following 3 lines into PowerShell (same for Windows PowerShell and VS Code):

1..3 |
# I do 't expect an error here
ForEach-Object { $_ }

Expected behavior

No errors, the commented line (# ...) to be neglected. Similar to putting the comment directly after the pipe character:

1..3 | # I don 't expect an error here
ForEach-Object { $_ }

Actual behavior

Error

Error details

>> # I don 't expect an error here
ParserError:
Line |
   1 |  1..3 |
     |        ~
     | An empty pipe element is not allowed.

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.6
PSEdition                      Core
GitCommitId                    7.2.6
OS                             Microsoft Windows 10.0.22000
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

2022-09-03_19h55_01

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mklement0commented, Sep 7, 2022

Indeed this relates to the specific pasting method being employed: simulated typing (which breaks) vs. pasting the multi-line string as a whole, and the issue is being tracked in:

To recap briefly:

  • On Windows, you can avoid the issue by using <kbd>Ctrl-V</kbd> for pasting; a fix being discussed for right-clicking - should it ever be implemented - would have to guess what constitutes a single paste action based on which simulated keystrokes occur in rapid succession.
  • On Unix-like platforms: I think we’ll have to wait for PSReadLine to support paste bracketing (at least in my macOS terminals I currently see the problem).
0reactions
mklement0commented, Sep 7, 2022

As an aside: It is a separate issue, but it is curious that parsing stops after the comment line and considers the statement complete, given that it would make more sense to keep reading, based on the pending |.

A more obvious example would be to try to paste the following (PS Core now allows placing the | on the next line):

# Breaks when pasted with right-clicking on Windows and in Unix terminals
1..3
  | Write-Output
Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't paste a comment (`#`) after a pipe (`|`) and a newline
Can't paste a comment (`#`) after a pipe (`|`) and a newline · Summary · Jobs. reminder · Run details. Usage · Workflow...
Read more >
Commenting in a Bash script inside a multiline command
The reason $(#comment) doesn't work is because once it sees the # , it treats the rest of the line as comments, including...
Read more >
How to get a new line at the end of pipe command
I'm having trouble to make the output of the following command to be all at the same line, and then have a new...
Read more >
What's the point in adding a new line to the end of a file?
There are/were some C compilers that cannot parse the last line if it does not end with a newline. The C standard specifies...
Read more >
Paste command in Linux with examples
Paste command is one of the useful commands in Unix or Linux operating system. It is used to join files horizontally (parallel merging)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found