Vscode-powershell: Language server sometimes crashes then $ErrorActionPreference = "Stop"

Created on 17 May 2016  路  6Comments  路  Source: PowerShell/vscode-powershell

vscode: 1.1.1
Powershell: 0.6.1
Windows 10 x64 1511

I'm seeing a lot of crashes: (logfile is attached)

5/17/2016 11:39:24 AM [VERBOSE] - Method "OnSessionStateChanged" at line 694 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Session\PowerShellContext.cs
    Session state changed --

        Old state: Running
        New state: Ready
        Result: Failed
5/17/2016 11:39:24 AM [ERROR] - Method "ExecuteCommand" at line 402 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Session\PowerShellContext.cs
    Runtime exception occurred while executing command:

    System.Management.Automation.ActionPreferenceStopException: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: The term 'Get-Comm' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
       at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
       at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
       at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
       at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
       at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
       at System.Management.Automation.PowerShell.Invoke[T]()
       at System.Threading.Tasks.Task`1.InnerInvoke()
       at System.Threading.Tasks.Task.Execute()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.PowerShellContext.<ExecuteCommand>d__35`1.MoveNext()
5/17/2016 11:39:24 AM [ERROR] - Method "CurrentDomain_UnhandledException" at line 178 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Host\Program.cs
    FATAL UNHANDLED EXCEPTION:

    System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.ArgumentNullException: Value cannot be null.
    Parameter name: source
       at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
       at Microsoft.PowerShell.EditorServices.LanguageService.<GetCommandInfo>d__20.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.LanguageService.<FindParameterSetsInFile>d__18.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.Server.LanguageServer.<HandleSignatureHelpRequest>d__24.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<DispatchMessage>d__32.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<ListenForMessages>d__31.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Utility.AsyncContext.Start(Func`1 asyncMainFunc)
       at System.Threading.Tasks.Task.Execute()
       --- End of inner exception stack trace ---
       --- End of inner exception stack trace ---
       at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
       at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.ProtocolEndpoint.WaitForExit()
       at Microsoft.PowerShell.EditorServices.Host.Program.Main(String[] args)
    ---> (Inner Exception #0) System.AggregateException: One or more errors occurred. ---> System.ArgumentNullException: Value cannot be null.
    Parameter name: source
       at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
       at Microsoft.PowerShell.EditorServices.LanguageService.<GetCommandInfo>d__20.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.LanguageService.<FindParameterSetsInFile>d__18.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.Server.LanguageServer.<HandleSignatureHelpRequest>d__24.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<DispatchMessage>d__32.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<ListenForMessages>d__31.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Utility.AsyncContext.Start(Func`1 asyncMainFunc)
       at System.Threading.Tasks.Task.Execute()
       --- End of inner exception stack trace ---
    ---> (Inner Exception #0) System.ArgumentNullException: Value cannot be null.
    Parameter name: source
       at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
       at Microsoft.PowerShell.EditorServices.LanguageService.<GetCommandInfo>d__20.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.LanguageService.<FindParameterSetsInFile>d__18.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.Server.LanguageServer.<HandleSignatureHelpRequest>d__24.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<DispatchMessage>d__32.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<ListenForMessages>d__31.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Utility.AsyncContext.Start(Func`1 asyncMainFunc)
       at System.Threading.Tasks.Task.Execute()<---
    <---

EditorServices.zip

Issue-Bug

All 6 comments

Hmm, seems like you've got $ErrorActionPreference = "Stop" somewhere in your script or profile, correct? Looks like I'm not correctly handling the exception that gets thrown in some cases when this is turned on. I was able to get it to repro by setting my ErrorActionPreference and then hovering over a function defined in the same file. I'll look into it.

Thanks for the report!

You are correct. I have $ErrorActionPreference = "Stop" in my profile. Not sure that I need it anymore. :) Thanks for the great product btw!

However, now that I think about it, I will use ErrorActionPreference in scripts and test them via Pester, so better handling might be in order.

Yep, I need to ensure that it'll be handled correctly no matter what. I just found the issue actually, might have a fix out today.

Fixed it in PowerShellEditorServices. Might see if I can grab another couple more fixes tomorrow to put into a patch release.

Just shipped an update of the extension with this fix included! Sorry it took so long to get that out.

Was this page helpful?
0 / 5 - 0 ratings