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
Contributor

@rjmholt rjmholt commented Aug 1, 2019

@rjmholt rjmholt requested a review from TylerLeonhardt August 1, 2019 20:10
@rjmholt
Copy link
Contributor Author

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

@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
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry @rkeithhill, are you for this change?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

@rkeithhill rkeithhill Aug 14, 2019

Choose a reason for hiding this comment

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

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
Contributor Author

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

Choose a reason for hiding this comment

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

LGTM

@rjmholt rjmholt merged commit 974bb1d into PowerShell:master Aug 19, 2019
rjmholt added a commit to rjmholt/PowerShellEditorServices that referenced this pull request Aug 21, 2019
rjmholt added a commit that referenced this pull request Aug 21, 2019
@rjmholt rjmholt deleted the fix-git-uri branch December 11, 2019 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Starting debug crashes PowerShell session if project is in onedrive folder
3 participants