★ wanayoo — archive 1999 https://github.com/PowerShell/PowerShellEditorServices/pull/1000Nouvelle recherche | Portail wanayoo
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

Fix crash when setBreakpoint from VSCode sends a git:/ URI... #1000

Merged
merged 2 commits into from Aug 19, 2019

Conversation

@rjmholt
Copy link
Member

@rjmholt rjmholt commented Aug 1, 2019

@rjmholt rjmholt requested a review from TylerLeonhardt Aug 1, 2019
@rjmholt
Copy link
Member Author

@rjmholt rjmholt commented Aug 1, 2019

Wait, it looks like we already have a test for a path like this and it's expected as a possible in-memory input path:

string shortUriForm = "git:/c%3A/Users/Keith/GitHub/dahlbyk/posh-git/src/PoshGitTypes.ps1?%7B%22path%22%3A%22c%3A%5C%5CUsers%5C%5CKeith%5C%5CGitHub%5C%5Cdahlbyk%5C%5Cposh-git%5C%5Csrc%5C%5CPoshGitTypes.ps1%22%2C%22ref%22%3A%22~%22%7D";

@rkeithhill is it possible this is already fixed?

@TylerLeonhardt
Copy link
Member

@TylerLeonhardt TylerLeonhardt commented Aug 1, 2019

@rjmholt multiple folks mentioned the debug adapter in the issues... it could be a different code path?

@@ -174,6 +180,20 @@ public ScriptFile GetFile(string filePath)
/// <param name="scriptFile">The out parameter that will contain the ScriptFile object.</param>
public bool TryGetFile(string filePath, out ScriptFile scriptFile)
{
try
{
if (filePath.Contains(":/") // Quick heuristic to determine if we might have a URI

This comment has been minimized.

@rkeithhill

rkeithhill Aug 2, 2019
Collaborator

I thought I had suggested a code change like this before but we eventually decided that the GetFile() call on line 199 would throw in this case and we'd return false. That said, I'd rather test this in a way that doesn't rely on catching an exception.

This comment has been minimized.

@TylerLeonhardt

TylerLeonhardt Aug 6, 2019
Member

Sorry @rkeithhill, are you for this change?

This comment has been minimized.

@rkeithhill

rkeithhill Aug 6, 2019
Collaborator

Yes.

This comment has been minimized.

@rjmholt

rjmholt Aug 6, 2019
Author Member

My worry is that there seems to be a test that exists already for a git:/ schemed file. My change would just reject those (and anything else that isn't file, untitled or inmemory). The fact that we already have a test for this makes me feel like there is an expectation that we can understand and handle a URI like this -- does that seem right?

This comment has been minimized.

@rkeithhill

rkeithhill Aug 14, 2019
Collaborator

Those tests for git:/ and gitlens-git:/ look like my tests. I think the intent here was to have those uri schemes return true for IsInMemory which we used to signal that you can't do things like set breakpoints with an "in memory" document. In retrospect, perhaps that is not the best approach RE the way we used IsInMemory but the basic idea was to determine whether or not we had a file path we could provide to Set-PSBreakpoint.

This comment has been minimized.

@rkeithhill

rkeithhill Aug 14, 2019 •
Collaborator

In an ideal design, I could walk up to the ScriptFile/EditorDocument and query a property like CanHaveBreakpoints or something like that to determine whether or not an LSP text document could have a breakpoint set on it. But I think this is good as a stop-gap. Ship it! :shipit:

@rjmholt
Copy link
Member Author

@rjmholt rjmholt commented Aug 2, 2019

multiple folks mentioned the debug adapter in the issues... it could be a different code path?

The stack trace I'm working against looks like this:

    System.AggregateException: One or more errors occurred. ---> System.ArgumentException: Illegal characters in path.
       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.Workspace.TryGetFile(String filePath, ScriptFile& scriptFile)
       at Microsoft.PowerShell.EditorServices.Protocol.Server.DebugAdapter.<HandleSetBreakpointsRequest>d__30.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.ArgumentException: Illegal characters in path.
       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.Workspace.TryGetFile(String filePath, ScriptFile& scriptFile)
       at Microsoft.PowerShell.EditorServices.Protocol.Server.DebugAdapter.<HandleSetBreakpointsRequest>d__30.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()<---

So Workspace.TryGetFile seems like the right place. What I don't understand is that we seem to have already dealt with this kind of URI scheme elsewhere, but we're still throwing here...

Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

LGTM

@rjmholt rjmholt merged commit 974bb1d into PowerShell:master Aug 19, 2019
8 checks passed
8 checks passed
Codacy/PR Quality Review Up to standards. A positive pull request.
Details
PowerShellEditorServices-CI Build #PR-1000-20190801.02 succeeded
Details
PowerShellEditorServices-CI (PowerShell 5.1 | Windows 10) PowerShell 5.1 | Windows 10 succeeded
Details
PowerShellEditorServices-CI (PowerShell 6 | Ubuntu) PowerShell 6 | Ubuntu succeeded
Details
PowerShellEditorServices-CI (PowerShell 6 | Windows 10) PowerShell 6 | Windows 10 succeeded
Details
PowerShellEditorServices-CI (PowerShell 6 | macOS) PowerShell 6 | macOS succeeded
Details
PowerShellEditorServices-secret-scan #PR-1000-20190801.02 succeeded
Details
license/cla All CLA requirements met.
Details
rjmholt added a commit to rjmholt/PowerShellEditorServices that referenced this pull request Aug 21, 2019
…hell#1000)

* Fix git uri problem

* Remove unused imports
rjmholt added a commit that referenced this pull request Aug 21, 2019
…#1012)

* Fix git uri problem

* Remove unused imports
@rjmholt rjmholt deleted the rjmholt:fix-git-uri branch Dec 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants
You can’t perform that action at this time.