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

Errors in Integrated Console when invoking some native applications (PSHostRawUserInterface) #972

Closed
ChrisWarwick opened this issue Jul 24, 2017 · 10 comments

Comments

@ChrisWarwick
Copy link

System Details

  • Operating system name and version: Windows 10 Insider 16232
  • VS Code version: 1.14.1
  • PowerShell extension version: 1.4.1
  • Output from $PSVersionTable:
    Name Value

PSVersion 5.1.16232.1000
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.16232.1000
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Copy / paste the below commands into the PowerShell Integrated Terminal, and paste the output here

code -v
$pseditor.EditorServicesVersion
code --list-extensions --show-versions
$PSVersionTable

Issue Description

In VSCode Integrated Terminal when using "Start-Transcript", external commands (e.g. git.exe/ipconfig/nbtstat/etc/etc/etc) run as expected, but on completion a spurious error message is displayed.

This occurs if Start-Transcript is entered manually into the integrated console or if Start-Transcript is included in Profile.ps1. The error does not occur if transcripts are not being collected (or if Stop-Transcript is used).

The issue only occurs with external (.exe/.com etc) commands. Cmdlets do not cause a problem.

(I have tested with no profile scripts to eliminate anything in my profile)

More info available on request....

Attached Logs

#Example

PS C:\Data\Git> Start-Transcript -OutputDirectory 'C:\Data'
PS C:\Data\Git>
PS C:\Data\Git> arp /?

Displays and modifies the IP-to-Physical address translation tables used by
<...snip...>

arp -a .... Displays the arp table.
Program 'ARP.EXE' failed to run: The method or operation is not implemented.At line:1 char:1

  • arp /?

At line:1 char:1

  • arp /?
  •   + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
      + FullyQualifiedErrorId : NativeCommandFailed
    
    

PS C:\Data\Git>

@dlwyatt
Copy link

dlwyatt commented Sep 7, 2017

I'm seeing these errors even if transcription isn't running.

Edit: Nevermind, transcription is running, enforced by policy.

@daviwil daviwil added this to the Future milestone Sep 7, 2017
@daviwil
Copy link
Contributor

daviwil commented Sep 7, 2017

@gerane has reported this as well. The core problem here is that the native app you're calling is doing something that causes one of the PSHostRawUserInterface methods I don't implement to be called so it fails. The solution is to provide a more complete implementation there (though I'd rather find a way to reuse the real PowerShell ConsoleHost so that we can get past all of the current limitations).

@daviwil daviwil changed the title Spurious Error in integrated console when using external commands with transcript enabled. Errors in Integrated Console when invoking some native applications (PSHostRawUserInterface) Sep 7, 2017
@dlwyatt
Copy link

dlwyatt commented Sep 7, 2017

In my case, it happens on every external command I run. Here's the innermost exception:

Message        : The method or operation is not implemented.
Data           : {}
InnerException :
TargetSite     : System.Management.Automation.Host.BufferCell[,] GetBufferContents(System.Management.Automation.Host.Rectangle)
StackTrace     :    at Microsoft.PowerShell.EditorServices.TerminalPSHostRawUserInterface.GetBufferContents(Rectangle rectangle)
                    at System.Management.Automation.Internal.Host.InternalHostRawUserInterface.GetBufferContents(Rectangle r)
                    at System.Management.Automation.NativeCommandProcessor.Complete()
HelpLink       :
Source         : Microsoft.PowerShell.EditorServices
HResult        : -2147467263

@dlwyatt
Copy link

dlwyatt commented Sep 7, 2017

Interestingly, GetBufferContents is only called by NativeCommandProcessor.Complete() in a block where it's supposedly transcribing. But if I run Stop-Transcript, it tells me the host is not transcribing. I'll do some more digging to find out what's going on there.

@dlwyatt
Copy link

dlwyatt commented Sep 7, 2017

Heh, nevermind. Company's saving powershell transcripts via policy. :)

@gerane
Copy link

gerane commented Sep 7, 2017

@ChrisWarwick @daviwil @dlwyatt oh! great find. I just tested and disabled the transcription policies and the errors stopped happening.

I can at least make sure this is disabled when doing presentations or demos now, but would be great to see this fixed.

@gerane
Copy link

gerane commented Sep 7, 2017

@daviwil @ChrisWarwick @dlwyatt The issue I encounter, is that depending on how the commands were invoked, these can become terminating errors.

For example, I have a function that runs a plaster template to create a new project, and also initializes the git repo and a bunch of other related tasks. If I run the command in the console, I get errors, but they are non-terminating. If I run this from an Editor Command, it breaks and causes these errors to be terminating errors.

@daviwil
Copy link
Contributor

daviwil commented Sep 7, 2017

@dlwyatt Thanks Dave! I don't know why I didn't look at the call stack and actually figure out why this was happening. Looks like if I implement the method enough to satisfy this code the problem should go away:

https://github.com/PowerShell/PowerShell/blob/7c9b188c135ed001093641698d48a22fd016f6ab/src/System.Management.Automation/engine/NativeCommandProcessor.cs#L713

I'll try to throw that in with the next Editor Services update.

@gerane
Copy link

gerane commented Sep 7, 2017

@daviwil Here is my issue from PSES PowerShell/PowerShellEditorServices#396

@BladeFireLight
Copy link

I looking forward to this fix. We have transcription on via Policy also.
right now any try/catch with a native command fails 100% of the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants