PowerShell / vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code
https://marketplace.visualstudio.com/items/ms-vscode.PowerShell
MIT License
1.7k stars 490 forks source link

Debug adapter process terminated unexpectedly and PowerShell session has terminated due to an error at the same time and all time #1078

Closed Cognic closed 6 years ago

Cognic commented 6 years ago

System Details


code -v : 
1.17.2
b813d12980308015bcd2b3a2f6efa5c810c33ba5

$pseditor.EditorServicesVersion:
Major  Minor  Build  Revision
-----  -----  -----  --------
1      5      0      0

code --list-extensions --show-versions:
azemoh.one-monokai@0.3.4
donjayamanne.python@0.7.0
joshpeng.sublime-babel-vscode@0.2.9
joshpeng.theme-onedark-sublime@0.3.6
jprestidge.theme-material-theme@1.0.1
magicstack.MagicPython@1.0.12
ms-vscode.csharp@1.12.1
ms-vscode.PowerShell@1.5.0
robertohuertasm.vscode-icons@7.17.0
rokoroku.vscode-theme-darcula@1.0.13
tht13.python@0.2.3

$PSVersionTable:
Name                           Value                                                                                                                                     
----                           -----                                                                                                                                     
PSVersion                      5.1.14393.1532                                                                                                                            
PSEdition                      Desktop                                                                                                                                   
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                   
BuildVersion                   10.0.14393.1532                                                                                                                           
CLRVersion                     4.0.30319.42000                                                                                                                           
WSManStackVersion              3.0                                                                                                                                       
PSRemotingProtocolVersion      2.3                                                                                                                                       
SerializationVersion           1.1.0.1 

Issue Description:

"Debug adapter process has terminated unexpectedly" "The PowerShell session has terminated due to an error, would you like to restart"

These two errors keeps popping up every time I run something from VScode, not even while debugging. VSCode has been my primary editor for long but these days its very annoying to keep switching between VSCode for writing and ISE for debugging and running. Please fix.

Attached Logs

logs.zip

ZHumphries commented 6 years ago

I get exactly the same error when attempting to attach to a powershell process to debug.

Halkcyon commented 6 years ago

Same VSCode and extension versions. PowerShell debugging does not work. No output to the debug console, session crashes constantly. Completely useless for debugging still. It's a bit frustrating to have to go back to the ISE to properly test anything.

rkeithhill commented 6 years ago

I see what the problem is here. I believe we can get this fixed for the next drop. BTW the problem pointed out by the log for this issue is the existence of an 'Untitled" editor window open in the workspace. If there is a breakpoint set in an unsaved file, we can't break on it. The PowerShell debug engine requires a filename and a line number. And even before it gets to that point, path handling code chokes on "untitled:Untitled-3".

rkeithhill commented 6 years ago

I was puzzled how to repro this. Finally figured it out. If you diff a PS1 file and then in the diff viewer, set a breakpoint in the right pane, a breakpoint of the form Untitled-X will show up in the breakpoints view. We can't set a line breakpoint unless we have a full file path. So long story short, we'll fix the crash but breakpoints set in the right pane of the Git diff viewer will not work.

Cognic commented 6 years ago

Thanks Keith for picking it up. I have closed the untitled-X file and opened a saved script and tried to debug and its still the same error. Thought of letting you know. Thanks.

rkeithhill commented 6 years ago

Can you attach the zipped log file for such a session?

MRWeather commented 6 years ago

If you set a breakpoint in a non-saved file, then close that file without saving, the breakpoint remains in the breakpoint list and the debugger crashes. Even disabling the Untitled-x breakpoint causes the debugger to crash. If you remove all breakpoints and add a breakpoint to a saved file, the debugger works as expected. Seems like it should either prevent breakpoints on unsaved files (since they don't seem to work anyway) or remove any breakpoints on unsaved files when the file is closed and not saved. $.02

rkeithhill commented 6 years ago

@MRWeather I believe I have that particular crash fixed. I think @Cognic is running into a different bug now but hard to tell unless I can get the log files.

MRWeather commented 6 years ago

OK. It sounded the same to me - for me it wasn't the open unsaved file, but a breakpoint for any unsaved file that was causing the problem. If @Cognic had a breakpoint for an unsaved file, closing the file and opening a different one without removing the bad breakpoint would not do anything.

Either way, thanks for working on this - I hope you get lots of appreciation :)

rkeithhill commented 6 years ago

No worries. Glad to have to the extra info!

Cognic commented 6 years ago

@rkeithhill Attached the logs. Thanks.

logs_v1.zip

ZHumphries commented 6 years ago

for me its reproducible by simply opening a clean install of VSCode and attaching the debugger to an external powershell process. (Without opening any files/directories first)

rkeithhill commented 6 years ago

@ZHumphries That is a different bug related to debugging that is being tracked here

rkeithhill commented 6 years ago

@Cognic This looks to be the exact same issue as before:

11/8/2017 10:10:13 AM [VERBOSE] - Method "ReadMessage" at line 123 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageReader.cs

    Received Request 'setBreakpoints' with id 3

11/8/2017 10:10:13 AM [VERBOSE] - Method "ResolveFilePath" at line 354 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Workspace\Workspace.cs

    Resolved path: untitled:Untitled-3

11/8/2017 10:10:13 AM [ERROR] - Method "OnListenTaskCompleted" at line 391 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\ProtocolEndpoint.cs

    ProtocolEndpoint message loop terminated due to unhandled exception:

    System.AggregateException: One or more errors occurred. ---> System.NotSupportedException: The given path's format is not supported.
       at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)
       at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
       at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
       at Microsoft.PowerShell.EditorServices.Workspace.GetFile(String filePath)
       at Microsoft.PowerShell.EditorServices.Protocol.Server.DebugAdapter.<HandleSetBreakpointsRequest>d__25.MoveNext()

I wonder if you're seeing what @MRWeather points out above. That is, you don't have an "Untitled-3" window open but at some point you did and you set a breakpoint in it and closed that window. But the breakpoint hung around. If you look in the Breakpoints view, do you see a breakpoint set on "Untitled-3"? If so, right-click and remove that breakpoint. That should get you debugging again.

Cognic commented 6 years ago

@rkeithhill Sorry I forgot to mention that I have tried what @MRWeather pointed out and didn't work. Now there was a new version got pushed 1.18.0 which seems to have fixed the debugging issue. Thank you.

rkeithhill commented 6 years ago

Ah, looks like they fixed the VSCode side of the debugger. I'm still going to commit my changes to make the PowerShell side more resilient to this.

MRWeather commented 6 years ago

The breakpoint on an unsaved file is still an issue for me even with the new VSCode.

rkeithhill commented 6 years ago

I believe this particular issue has been fixed. If I haven't heard otherwise in a few days, I'm going to close this issue.

MRWeather commented 6 years ago

I believe it is fixed. I have tested the conditions that I reported and the debugger doesn't crash.

I still think it is odd that you can set a breakpoint in an unsaved file when it won't break on it. And if you save after setting a breakpoint, the Untitled-x breakpoint remains in the list of breakpoints. I know these warrant another issue. So the symptom is fixed, I have no problem with this issue being closed.

rkeithhill commented 6 years ago

@MRWeather Thanks for following up. Yeah, there are some oddities with the interaction (or lack thereof) between the VSCode debug breakpoint UI and the target debugger - which doesn't actually get invoked until the user starts debugging.