Skip to content

PowerShell extension crashes when dealing with UNC paths #1830

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

Closed
BruceAWilliams opened this issue Mar 31, 2019 · 20 comments
Closed

PowerShell extension crashes when dealing with UNC paths #1830

BruceAWilliams opened this issue Mar 31, 2019 · 20 comments
Assignees
Labels
Area-Pester Issue-Bug A bug to squash.

Comments

@BruceAWilliams
Copy link

System Details

System Details Output


Issue Description

I am experiencing a problem with...

Expected Behaviour

-- Description of what should be happening --

Actual Behaviour

-- Description of what actually happens --

Attached Logs

Follow the instructions in the troubleshooting docs
about capturing and sending logs.

@rkeithhill
Copy link
Contributor

Please attach logs - see the troubleshooting docs. Without version info (extension, vscode, os), logs and/or repro instructions, this issue isn't very actionable.

@BruceAWilliams
Copy link
Author

Just doing that now, I thought I had attached them

@BruceAWilliams
Copy link
Author

BruceAWilliams commented Mar 31, 2019

Issue Description:

CodeLens is causing interactive powershell console to crash
This is similar to the issue #887
I'm wondering if a solution for this issue has been found.

I'm seeing the same behavior both with code in the repo (github and Enterprise), it seems to have just started a week ago or so, after adding the latest upgrade. The video shown here is the same thing i'm seeing.

System Details:

[system.environment]::OsVersion.Version *
Major Minor Build Revision
6 3 9600 0

PS> code -v
1.32.3
a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4
x64

PS> $PsVersionTable
Name Value
PSVersion 5.1.14409.1018
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14409.1018
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

PS> $pseditor.EditorServicesVersion
Major Minor Build Revision
1 12 0 0

### Expected Behavior
Codlens places a reference comment above a function

Actual Behavior
for this example: After entering a function scriptblock, the codelens seems to want to a reference above the scriptblock, moves the block down, looks like its trying, but then fails the block moves backup and the interactive console crashes.

Logfiles:

EditorServices.log

vscode-powershell.log

2019-03-31_10-22-05

@ili101
Copy link

ili101 commented Apr 1, 2019

vscode-powershell.log
EditorServices.log
Same Problem but the error in my logs is different, It happens to me when the file with the function is on a network share (\\server\path\file.ps1) if the file is local it's not crashing for me. as @BruceAWilliams shows with CodeLens disabled it's not crashing.

@ThubLives
Copy link

I'm seeing the same behaviour as @ili101. Local files are fine, but scripts located at UNC paths exhibit crashing.

@SydneyhSmith SydneyhSmith added Issue-Bug A bug to squash. Area-Pester Issue-Performance Something's slow. labels Apr 1, 2019
@rjmholt
Copy link
Contributor

rjmholt commented Apr 2, 2019

The relevant log entry seems to be this one:

2019-04-01 12:36:03.813 [ERROR] tid:5 in 'OnListenTaskCompleted' C:\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\ProtocolEndpoint.cs: line 391
    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.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
       at Microsoft.PowerShell.EditorServices.Workspace.ResolveFilePath(String filePath)
       at Microsoft.PowerShell.EditorServices.Workspace.GetFile(String filePath)
       at Microsoft.PowerShell.EditorServices.CodeLenses.CodeLensFeature.<HandleCodeLensResolveRequest>d__6.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.NotSupportedException: The given path's format is not supported.
       at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)
       at System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
       at Microsoft.PowerShell.EditorServices.Workspace.ResolveFilePath(String filePath)
       at Microsoft.PowerShell.EditorServices.Workspace.GetFile(String filePath)
       at Microsoft.PowerShell.EditorServices.CodeLenses.CodeLensFeature.<HandleCodeLensResolveRequest>d__6.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()<---
    

It seems to be occurring in this method: https://github.com/PowerShell/PowerShellEditorServices/blob/8c66fa912ecfac4e93345ca96dc49d1787f81f1d/src/PowerShellEditorServices/Workspace/Workspace.cs#L464-L487

Whatever .NET API we're using to resolve file paths as URIs seems to not like UNC paths, so we'll need to determine what the best way to handle those is.

@adegutis
Copy link

adegutis commented Apr 4, 2019

I was experiencing the repeated PowerShell extension crash until I disabled Code Lens in settings. My logs also have the The given path's format is not supported. error as noted above. As others mentioned I have UNC paths in the script that load other functions via dot-sourcing. I also noticed that upon saving the file, the dot-sourced UNC path gets removed regardless if Code Lens is enabled or not. Example:

. \\server\gitmaster\functions\function.ps1

gets changed to this on save:

. function.ps1

I am working around it by using Set-Location to the path of the function before dot-sourcing the function which allows me to use . .\function.ps1 but I hope this gets addressed before I have to put that workaround into too many files.

@rkeithhill
Copy link
Contributor

Do you have this setting configured: "editor.formatOnSave": true? We believe there is an issue with code formatting that is removing parts of dot-sourced paths.

@adegutis
Copy link

adegutis commented Apr 4, 2019

Do you have this setting configured: "editor.formatOnSave": true? We believe there is an issue with code formatting that is removing parts of dot-sourced paths.

Yes I do. I will disable it for the near-term. Thanks!

@mmmStefan
Copy link

I'm having the same experience as the first posts where I have files on a network share. Loading local files works better without crashes, but there are still issues with "X references" for each function.

I'm having this issues without using any UNC paths inside my ps1 files. Didn't have these issues prior to 1.12.0.
powershell_vsc

@rkeithhill
Copy link
Contributor

Can you attach log files for the extension? See troubleshooting docs for instructions on how to do that.

@rkeithhill
Copy link
Contributor

@BruceAWilliams I think I've fixed the UNC path issues other folks are seeing but your log isn't detailed enought to see what is going on. Can you set your log level to diagnostic temporarily, repro the issue and attach the logs here? Thanks.

Put this in you user settings file to enable diagnostic level logging:

    "powershell.developer.editorServicesLogLevel": "Diagnostic",

@mmmStefan
Copy link

mmmStefan commented Apr 5, 2019

I saw that my VSC loaded some UNC-path dirs, even though I don't open the files themselves.
EditorServices.log
metadata.txt
vscode-powershell.log

@rjmholt
Copy link
Contributor

rjmholt commented Apr 5, 2019

I saw that my VSC loaded some UNC-path dirs, even though I don't open the files themselves.

It's trying to resolve references in the script; it starts from what you've got open and works backwards.

@BruceAWilliams
Copy link
Author

BruceAWilliams commented Apr 6, 2019

@TylerLeonhardt TylerLeonhardt changed the title CodeLens is causing interactive powershell console to crash PowerShell extension crashes when dealing with UNC paths Apr 8, 2019
@TylerLeonhardt
Copy link
Member

Hi all, can you try one of these builds:

PowerShell and PowerShell Preview release candidates.zip

This should have the UNC path fix. Note, if you've never used the Preview extension, look at these steps.

If you've never installed a VSIX before, here are the steps.

@adegutis
Copy link

I installed the the v1.12.1 extension, reloaded vscode and when I executed Import-module \\saas\saasops\Users\Al\Github\certificate-tracking\CertificateTracking.psd1 in the vscode terminal window, it threw the error below. Executing the import-module a second time ran without error. Not sure if this is specific to my set up but thought I'd share it.

Exception             : System.Management.Automation.MethodInvocationException: Exception calling "InvokeScript" with "4" argument(s): "Index was outside the bounds of the array." ---> 
                        System.Management.Automation.CmdletInvocationException: Index was outside the bounds of the array. ---> System.IndexOutOfRangeException: Index was outside the 
                        bounds of the array.
                           at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
                           at Sqlcollaborative.Dbatools.Commands.SetDbatoolsConfigCommand.ExecuteInitialize() in 
                        F:\Code\Github\dbatools\bin\projects\dbatools\dbatools\Commands\SetDbatoolsConfigCommand.cs:line 308
                           at Sqlcollaborative.Dbatools.Commands.SetDbatoolsConfigCommand.ProcessRecord() in 
                        F:\Code\Github\dbatools\bin\projects\dbatools\dbatools\Commands\SetDbatoolsConfigCommand.cs:line 275
                           at System.Management.Automation.CommandProcessor.ProcessRecord()
                           --- End of inner exception stack trace ---
                           at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
                           at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
                           at System.Management.Automation.ScriptBlock.InvokeWithPipeImpl(ScriptBlockClauseToInvoke clauseToInvoke, Boolean createLocalScope, Dictionary`2 
                        functionsToDefine, List`1 variablesToDefine, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, 
                        InvocationInfo invocationInfo, Object[] args)
                           at System.Management.Automation.ScriptBlock.<>c__DisplayClass57_0.<InvokeWithPipe>b__0()
                           at System.Management.Automation.Runspaces.RunspaceBase.RunActionIfNoRunningPipelinesWithThreadCheck(Action action)
                           at System.Management.Automation.ScriptBlock.InvokeWithPipe(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, 
                        Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Boolean propagateAllExceptionsToTop, List`1 variablesToDefine, Dictionary`2 functionsToDefine, 
                        Object[] args)
                           at System.Management.Automation.ScriptBlock.DoInvokeReturnAsIs(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object 
                        input, Object scriptThis, Object[] args)
                           at System.Management.Automation.CommandInvocationIntrinsics.InvokeScript(ScriptBlock sb, Boolean useNewScope, PipelineResultTypes writeToPipeline, IList input, 
                        Object[] args)
                           at System.Management.Automation.CommandInvocationIntrinsics.InvokeScript(Boolean useLocalScope, ScriptBlock scriptBlock, IList input, Object[] args)
                           at CallSite.Target(Closure , CallSite , Object , Boolean , Object , Object , Object )
                           --- End of inner exception stack trace ---
                           at System.Management.Automation.ExceptionHandlingOps.ConvertToMethodInvocationException(Exception exception, Type typeToThrow, String methodName, Int32 numArgs, 
                        MemberInfo memberInfo)
                           at CallSite.Target(Closure , CallSite , Object , Boolean , Object , Object , Object )
                           at Import-ModuleFile(Closure , FunctionContext )
TargetObject          : 
CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : CmdletInvocationException
ErrorDetails          : 
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at Import-ModuleFile, C:\Users\dal\Documents\WindowsPowerShell\Modules\dbatools\0.9.715\dbatools.psm1: line 40
                        at <ScriptBlock>, C:\Users\dal\Documents\WindowsPowerShell\Modules\dbatools\0.9.715\dbatools.psm1: line 224
                        at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}
PSMessageDetails      : 

@TylerLeonhardt
Copy link
Member

@adegutis Looks like that's happening within dbatools. You might wanna point that over to them if it happens regularly.

@rkeithhill
Copy link
Contributor

@BruceAWilliams Can you try a special drop of the extension to see if it fixes the original issue you brought up? The instructions are in third message up from this one. Thanks!

@SydneyhSmith
Copy link
Collaborator

Closing as this fix has been merged and will be available in the next release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Pester Issue-Bug A bug to squash.
Projects
None yet
Development

No branches or pull requests

9 participants