Skip to content

Fix crash when seting PSSA rules w/Untitled active editor #606

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

Conversation

rkeithhill
Copy link
Contributor

Fix issue 1155 in vscode-powershell - PowerShell/vscode-powershell#1155

Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, Keith 😄 I think this crash happened to me today - thanks! 👍

@daviwil
Copy link
Contributor

daviwil commented Jan 12, 2018

I think that the Workspace should be able to retrieve an untitled file, right? I'm doing that in the DebugAdapter here:

https://github.com/PowerShell/PowerShellEditorServices/blob/master/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs#L91

What was the stack trace of the crash?

@rkeithhill
Copy link
Contributor Author

    System.AggregateException: One or more errors occurred. ---> System.IO.FileNotFoundException: Could not find file 'C:\Users\vndtekjxk\Documents\GitHub\ServiceDelivery\Untitled-1'.
       at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
       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.LanguageServer.<HandleSetPSSARulesRequest>d__19.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<DispatchMessage>d__7.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.ProtocolEndpoint.<ListenForMessages>d__36.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Utility.AsyncContext.Start(Func`1 asyncMainFunc, ILogger logger)
       at System.Threading.Tasks.Task.Execute()
       --- End of inner exception stack trace ---
    ---> (Inner Exception #0) System.IO.FileNotFoundException: Could not find file 'C:\Users\vndtekjxk\Documents\GitHub\ServiceDelivery\Untitled-1'.
    File name: 'C:\Users\vndtekjxk\Documents\GitHub\ServiceDelivery\Untitled-1'
       at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
       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.LanguageServer.<HandleSetPSSARulesRequest>d__19.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<DispatchMessage>d__7.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.ProtocolEndpoint.<ListenForMessages>d__36.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Utility.AsyncContext.Start(Func`1 asyncMainFunc, ILogger logger)
       at System.Threading.Tasks.Task.Execute()<---

Basically in the handler for setting PSSA rules, the code calls Workspace.GetFile() and that chokes on the filename.

@daviwil
Copy link
Contributor

daviwil commented Jan 12, 2018

I wonder if VS Code changed how they represent untitled paths? Can you tell what original path it was trying to resolve before that? Should start with untitled://

@rkeithhill
Copy link
Contributor Author

I was going to bring up at the PS Community mtg during the PSES part that I've seen a number of errors recently related to working with Untitled (in memory) files. I'm guilty of fixing them onesy/twosy. Could be I'm not seeing the proper API or maybe we need to attack the problem more holistically.

@rkeithhill
Copy link
Contributor Author

No, it was literally Untitled-1 in the debugger.

@daviwil
Copy link
Contributor

daviwil commented Jan 12, 2018

Found the true source of the problem:

https://github.com/PowerShell/vscode-powershell/blob/0adcd2bea8797d69230252ec8a8185236be77ecc/src/features/SelectPSSARules.ts#L52

I think you need to get rid of the fsPath at the end, the path needs to be in Uri format for untitled files to work.

@daviwil
Copy link
Contributor

daviwil commented Jan 12, 2018

Might require calling toString() on the Uri instance, to get the right Uri output

@rkeithhill
Copy link
Contributor Author

Check out the stack trace on this one #569 - same issue?

@daviwil
Copy link
Contributor

daviwil commented Jan 12, 2018

Nah, in this one VS Code sent us a totally invalid Uri, there's only 1 slash for the scheme git:/. I made the path handling more robust for dealing with unexpected schemes but I don't think I accounted for unparseable Uris:

daviwil@9b98c65

Might be worth checking if running the Git Diff viewering on a .ps1 file still causes this crash

@rkeithhill
Copy link
Contributor Author

rkeithhill commented Jan 12, 2018

So that other folks don't do this:

filePath: vscode.window.activeTextEditor.document.uri.fsPath

Should we create a helper method (getFilePathForPSES(doc)) to grab the proper form of the path for PSES? Maybe in utils.ts?

BTW uri.toString() returns this - vscode.window.activeTextEditor.document.uri.fsPath. Is that what you want?

@daviwil
Copy link
Contributor

daviwil commented Jan 12, 2018

hmmm... According to the API docs toString is supposed to give the full Uri path:

https://code.visualstudio.com/docs/extensionAPI/vscode-api#_a-nameuriaspan-classcodeitem-id373urispan

Weird that it'd return a string with .fsPath at the end. Is it possible to console.log() the whole uri object to see what it's got in it?

@rkeithhill
Copy link
Contributor Author

Fixed this a better way via - PowerShell/vscode-powershell#1244

@rkeithhill rkeithhill closed this Mar 24, 2018
@rkeithhill rkeithhill deleted the rkeithhill/fix-pssa-select-untitled branch March 24, 2018 05:26
@rkeithhill
Copy link
Contributor Author

Closing this as this has been fixed in vscode-powershell - PowerShell/vscode-powershell#1244

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

Successfully merging this pull request may close these issues.

3 participants