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

Starting PowerShell extension from VSCode results in PSReadLine error #4219

Closed
6 tasks done
cdonnellytx opened this issue Oct 21, 2022 · 7 comments · Fixed by PowerShell/PowerShellEditorServices#1936
Closed
6 tasks done
Assignees
Labels
Area-Engine Issue-Bug A bug to squash.

Comments

@cdonnellytx
Copy link

cdonnellytx commented Oct 21, 2022

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

When starting the PowerShell extension from VSCode, PSReadLine repeats the same error half a dozen times, and during early use of the terminal.

I have filed the issue with PSReadLine, but as the PowerShell extension was last released yesterday, and I cannot reproduce the problem when running from pwsh in VSCode or Windows Terminal, it appears to be an error with the plugin.

PowerShell Version

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

Visual Studio Code Version

1.72.2
d045a5eda657f4d7b676dedbfa7aab8207f8a075
x64

Extension Version

Steps to Reproduce

  1. Start Visual Studio Code
  2. Make sure the PowerShell extension is loaded. (Easiest way seems to be to open a .ps1 file in an editor tab.)

Visuals

PowerShell Extension screenshot

Logs

Oops, something went wrong.
Please report this bug with ALL the details below, including both the 'Environment' and 'Exception' sections.
Please report on GitHub: https://github.com/PowerShell/PSReadLine/issues/new?template=Bug_Report.yaml
Thank you!

### Environment
PSReadLine: 2.2.6
PowerShell: 2022.10.0
OS: Microsoft Windows 10.0.22000
BufferWidth: 210
BufferHeight: 26

Last 0 Keys:



### Exception

System.Management.Automation.PSInvalidOperationException: You should only run a nested pipeline from within a running pipeline.
   at System.Management.Automation.Runspaces.PipelineBase.DoConcurrentCheck(Boolean syncCall, Object syncObject, Boolean isInLock)
   at System.Management.Automation.Runspaces.RunspaceBase.DoConcurrentCheckAndAddToRunningPipelines(PipelineBase pipeline, Boolean syncCall)
   at System.Management.Automation.Runspaces.PipelineBase.CoreInvoke(IEnumerable input, Boolean syncCall)
   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
   at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke[T](IEnumerable input, IList`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke[T](IEnumerable input, PSInvocationSettings settings)
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility.PowerShellExtensions.InvokeAndClear[TResult](PowerShell pwsh, PSInvocationSettings invocationSettings) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Utility\PowerShellExtensions.cs:line 76
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility.PowerShellExtensions.InvokeCommand[TResult](PowerShell pwsh, PSCommand psCommand, PSInvocationSettings invocationSettings) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Utility\PowerShellExtensions.cs:line 99
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousPowerShellTask`1.ExecuteNormally(CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Execution\SynchronousPowerShellTask.cs:line 125
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousPowerShellTask`1.Run(CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Execution\SynchronousPowerShellTask.cs:line 77
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousTask`1.ExecuteSynchronously(CancellationToken executorCancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Execution\SynchronousTask.cs:line 92
--- End of stack trace from previous location ---
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousTask`1.get_Result() in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Execution\SynchronousTask.cs:line 58    
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousTask`1.ExecuteAndGetResult(CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Execution\SynchronousTask.cs:line 108
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Host.PsesInternalHost.InvokePSCommand[TResult](PSCommand psCommand, PowerShellExecutionOptions executionOptions, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Host\PsesInternalHost.cs:line 461
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Host.PsesInternalHost.InvokePSCommand(PSCommand psCommand, PowerShellExecutionOptions executionOptions, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Host\PsesInternalHost.cs:line 464
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Host.PsesInternalHost.OnPowerShellIdle(CancellationToken idleCancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Host\PsesInternalHost.cs:line 1140
   at Microsoft.PowerShell.PSConsoleReadLine.ReadKey()
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
@cdonnellytx cdonnellytx added the Issue-Bug A bug to squash. label Oct 21, 2022
@ghost ghost added the Needs: Triage Maintainer attention needed! label Oct 21, 2022
@andyleejordan
Copy link
Member

Hi,

Could you please provide more logging and environment information by following these steps?

Thanks!

@andyleejordan
Copy link
Member

Also helpful would be your profile / does it repro if you disable your profiles by setting powershell.enableProfileLoading to false.

@cdonnellytx
Copy link
Author

I tracked it down and found it is being caused by code in my profile. Specifically, a piece where I use Register-EngineEvent to import slower modules OnIdle so I can get my shell up more quickly but still have certain modules loaded for tab completion. I've reworked my profile so that it won't do that for the VSCode host, and that appears to have resolved it.

I did a little more testing and found out it is still reproducible even if you disable profile loading but call the following:

Register-EngineEvent -SourceIdentifier ([System.Management.Automation.PSEngineEvent]::OnIdle) -MaxTriggerCount 1 -Action { Write-Verbose "Test" }`

I also narrowed it down to changes in v2022.8.5-preview...v2022.9.0-preview by installing each of these Preview versions of the extension, but I don't see a specific commit in the diff that pops out to me as possibly having caused it.

@andyleejordan
Copy link
Member

andyleejordan commented Oct 24, 2022

Oh! Can you test v2022.10.0 and see if it still repros? We actually just fixed some bugs around the OnIdle handler in https://github.com/PowerShell/PowerShellEditorServices/pull/1918...so this is weird that at the same it fixed one issue, it caused another. Well, not that weird, it seemed like a hairy change.

@andyleejordan
Copy link
Member

Yeah still repros. Um, I think we broke it in a different way.

@andyleejordan
Copy link
Member

Hi @cdonnellytx! I think we just got this fixed in the PowerShell Preview for VS Code. Could you verify if this issue still reproduces using the preview extension?

@cdonnellytx
Copy link
Author

Looks like that fixed it. The issue does NOT reproduce with v2022.10.2. (The issue still reproduces with v2022.10.1, however.)

Thanks for fixing this @andschwa, I really appreciate it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Engine Issue-Bug A bug to squash.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants