-
Notifications
You must be signed in to change notification settings - Fork 318
Description
PSReadLine frequently (but inconsistently) throws an error when running multiline 'If' statements with uncuddled 'Else' clauses, either by Copy/Pasting the text into the terminal or using the "Run Selection" (F8) command in Visual Studio Code. It appears that sometimes PSReadLine is interpreting the pasted text as a multiline string/command (pasting the full content at once with the subsequent lines being preceded by ">>" instead of the normal prompt"), while other times each line is processed individually, causing the 'If' statement to be seen as concluded after it's closing brace, since the uncuddled 'Else' clause is not yet being processed.
The specific error text is this:
else : The term 'else' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
I have tested pasting/running the same text in terminals/shells both with and without PSReadLine loaded; the error receiving the pasted text never occurs when PSReadLine is unloaded, only occurring when PSReadLine has been imported. That being said, the error is inconsistent - there are times (though more infrequent) that I can paste text (or Run selection) and it is processed properly even with PSReadLine present, though most frequently the error is thrown. This inconsistency can be within a single session - the multiline statements are sometimes interpreted correctly several times before PSReadLine begins to fail processing (instead processing the input line-by-line rather than as one multiline command). Additionally, sometimes after the errors have been generated several times, suddenly the multiline command will begin being processed properly for a bit. It is wildly inconsistent.
Environment data
Issue encountered in multiple places:
(VS code terminal)
PS version: 5.1.18362.145
PSReadline version: 2.0.0-beta5
os: 10.0.18362.1 (WinBuild.160101.0800)
PS file version: 10.0.18362.1 (WinBuild.160101.0800)
HostName: ConsoleHost
BufferWidth: 236
BufferHeight: 19
(VS code integrated terminal)
PS version: 5.1.18362.145
PSReadline version: 2.0.0-beta5
os: 10.0.18362.1 (WinBuild.160101.0800)
PS file version: 10.0.18362.1 (WinBuild.160101.0800)
HostName: Visual Studio Code Host
BufferWidth: 236
BufferHeight: 19
(PS 6 shell)
PS version: 6.2.0
PSReadline version: 2.0.0-beta3
os: 10.0.18362.1 (WinBuild.160101.0800)
PS file version: 6.2.0.0
HostName: ConsoleHost
BufferWidth: 200
BufferHeight: 5000
(Windows PS 5.1 shell)
PS version: 5.1.18362.145
PSReadline version: 2.0.0-beta5
os: 10.0.18362.1 (WinBuild.160101.0800)
PS file version: 10.0.18362.1 (WinBuild.160101.0800)
HostName: ConsoleHost
BufferWidth: 120
BufferHeight: 3000
Steps to reproduce or exception report
Using the following sample code:
$service = Get-Service -Name wuauserv
if ($service.Status -eq "Running")
{
Write-Host "Service $($service.ServiceName) is Running"
}
elseif ($service.Status -eq "Stopped")
{
Write-Host "Service $($service.ServiceName) is Stopped"
}
else
{
Write-Host "Service $($service.ServiceName) is neither Running nor Stopped. It's actual status is $ ($service.Status)."
}
In a PowerShell terminal in VSCode or a PowerShell shell (tested in v5.1 and v6.2), paste the above text, without pressing 'Enter'.
Desired Result:


(this second image has the PSReadLine module removed first because I was not lucky enough to be able to reproduce the desired result while the module was installed. This does also illustrate that the problem does not exist when the module is not installed.)

