PowerShellEditorServices icon indicating copy to clipboard operation
PowerShellEditorServices copied to clipboard

System.NullReferenceException: Object reference not set to an instance of an object

Open eggcaker opened this issue 3 years ago • 5 comments

I'm using doom-emacs with lsp mode, after install all components automatically. got error pop up

LSP :: Error from the Language Server: Internal Error - System.NullReferenceException: Object reference not set to an instance of an object.

   at Microsoft.PowerShell.EditorServices.Services.AnalysisService.DelayThenInvokeDiagnosticsAsync(ScriptFile[] filesToAnalyze, CancellationToken cancellationToken) in D:\a\1\s\src\PowerShellEditorServices\Services\Analysis\AnalysisService.cs:line 384

   at Microsoft.PowerShell.EditorServices.Services.AnalysisService.GetMostRecentCodeActionsForFileAsync(DocumentUri uri) in D:\a\1\s\src\PowerShellEditorServices\Services\Analysis\AnalysisService.cs:line 235

   at Microsoft.PowerShell.EditorServices.Handlers.PsesCodeActionHandler.Handle(CodeActionParams request, CancellationToken cancellationToken) in D:\a\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CodeActionHandler.cs:line 59

   at OmniSharp.Extensions.LanguageServer.Server.Pipelines.SemanticTokensDeltaPipeline`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)

   at OmniSharp.Extensions.LanguageServer.Server.Pipelines.ResolveCommandPipeline`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)

   at MediatR.Pipeline.RequestPreProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)

   at MediatR.Pipeline.RequestPostProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)

   at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)

   at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)

   at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)

   at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)

   at OmniSharp.Extensions.JsonRpc.RequestRouterBase`1.<RouteRequest>g__InnerRoute|7_0(IServiceScopeFactory serviceScopeFactory, Request request, TDescriptor descriptor, Object params, CancellationToken token, ILogger logger)

   at OmniSharp.Extensions.JsonRpc.RequestRouterBase`1.RouteRequest(IRequestDescriptor`1 descriptors, Request request, CancellationToken token)

   at OmniSharp.Extensions.JsonRpc.InputHandler.<>c__DisplayClass38_0.<<RouteRequest>b__5>d.MoveNext() (Internal Error)

I'm using latest version of PowerShellEditorServices and on windows os.

eggcaker avatar Aug 03 '21 09:08 eggcaker

Hi, is this still reproducing with v2.5.1?

andyleejordan avatar Sep 09 '21 23:09 andyleejordan

not update yet , let me try install the 2.5.1

eggcaker avatar Sep 10 '21 03:09 eggcaker

same error with the latest version , zip file md5 : 6f6e0df4d869240227a952750747c572

eggcaker avatar Sep 12 '21 02:09 eggcaker

Thanks @eggcaker! I'll try to repro this and see how to fix it. Honestly I'd love to get a basic sanity test setup that runs PSES in Emacs and NeoVim in the CI.

andyleejordan avatar Sep 13 '21 17:09 andyleejordan

I'm using @hlissner/doom-emacs with lsp and (sh +lsp +powershell) modules btw.

eggcaker avatar Sep 14 '21 04:09 eggcaker

Hi, my name is klawrawkz. I am fine, how are you?

I get a similar error. I have not been able to track down a theoretical cause yet. The exception comes and goes like Michelangelo; today it has come, has not gone, continues to blow up, and is a real hassle because VSCode | POSH "intellisense" gets hosed and the only solution is to do a "F1 | > Developer: Reload Window" to get it working again.

I admit that I am not the most adept mathematician in the universe, however, based on my rudimentary calculations, it appears that this issue has been open for, oh, just a little shy of two (2.000000000000000) YEARS. I would really appreciate it if we could figure this out and create a solution. Hell, I don't really care what is causing the exception a this point. So I propose, at the very least, I mean just to get the ball rolling, how about we implement a try-catch that quietly, on the down-low, swallows the exception so it doesn't crash the intellisense in VS code? Then sometime down the road, perhaps far into the future, the exception will just work itself out. Like Milton is "worked out" as a problem in Office Space.

Here is the output from PowerShell Editor Services:

[Warn - 4:21:40 PM] OmniSharp.Extensions.LanguageServer.Server.Configuration.DidChangeConfigurationProvider: No ConfigurationItems have been defined, configuration won't surface any configuration from the client! | [Warn - 4:27:02 PM] Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler: Exception occurred while running handling completion request - System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.PowerShell.EditorServices.Services.Symbols.AstOperations.GetCompletionsAsync(Ast scriptAst, Token[] currentTokens, Int32 fileOffset, IInternalPowerShellExecutionService executionService, ILogger logger, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\Symbols\Visitors\AstOperations.cs:line 130 at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.GetCompletionsInFileAsync(ScriptFile scriptFile, Int32 lineNumber, Int32 columnNumber, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 205 at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.Handle(CompletionParams request, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 74 | [Warn - 4:27:12 PM] Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler: Exception occurred while running handling completion request - System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.PowerShell.EditorServices.Services.Symbols.AstOperations.GetCompletionsAsync(Ast scriptAst, Token[] currentTokens, Int32 fileOffset, IInternalPowerShellExecutionService executionService, ILogger logger, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\Symbols\Visitors\AstOperations.cs:line 130 at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.GetCompletionsInFileAsync(ScriptFile scriptFile, Int32 lineNumber, Int32 columnNumber, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 205 at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.Handle(CompletionParams request, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 74 | [Warn - 4:31:51 PM] Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler: Exception occurred while running handling completion request - System.Threading.Tasks.TaskCanceledException: A task was canceled. at Microsoft.PowerShell.EditorServices.Services.Symbols.AstOperations.GetCompletionsAsync(Ast scriptAst, Token[] currentTokens, Int32 fileOffset, IInternalPowerShellExecutionService executionService, ILogger logger, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\Symbols\Visitors\AstOperations.cs:line 85 at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.GetCompletionsInFileAsync(ScriptFile scriptFile, Int32 lineNumber, Int32 columnNumber, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 205 at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.Handle(CompletionParams request, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 74 | [Warn - 4:45:10 PM] Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler: Exception occurred while running handling completion request - System.Threading.Tasks.TaskCanceledException: A task was canceled. at Microsoft.PowerShell.EditorServices.Services.Symbols.AstOperations.GetCompletionsAsync(Ast scriptAst, Token[] currentTokens, Int32 fileOffset, IInternalPowerShellExecutionService executionService, ILogger logger, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\Symbols\Visitors\AstOperations.cs:line 141 at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.GetCompletionsInFileAsync(ScriptFile scriptFile, Int32 lineNumber, Int32 columnNumber, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 257 at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.Handle(CompletionParams request, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 91 | [Warn - 4:45:22 PM] Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler: Exception occurred while running handling completion request - System.Threading.Tasks.TaskCanceledException: A task was canceled. at Microsoft.PowerShell.EditorServices.Services.Symbols.AstOperations.GetCompletionsAsync(Ast scriptAst, Token[] currentTokens, Int32 fileOffset, IInternalPowerShellExecutionService executionService, ILogger logger, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\Symbols\Visitors\AstOperations.cs:line 141 at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.GetCompletionsInFileAsync(ScriptFile scriptFile, Int32 lineNumber, Int32 columnNumber, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 257 at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.Handle(CompletionParams request, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 91 | [Warn - 4:45:27 PM] Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler: Exception occurred while running handling completion request - System.Threading.Tasks.TaskCanceledException: A task was canceled. at Microsoft.PowerShell.EditorServices.Services.Symbols.AstOperations.GetCompletionsAsync(Ast scriptAst, Token[] currentTokens, Int32 fileOffset, IInternalPowerShellExecutionService executionService, ILogger logger, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\Symbols\Visitors\AstOperations.cs:line 141 at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.GetCompletionsInFileAsync(ScriptFile scriptFile, Int32 lineNumber, Int32 columnNumber, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 257 at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.Handle(CompletionParams request, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 91 | [Warn - 4:45:27 PM] Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler: Exception occurred while running handling completion request - System.Threading.Tasks.TaskCanceledException: A task was canceled. at Microsoft.PowerShell.EditorServices.Services.Symbols.AstOperations.GetCompletionsAsync(Ast scriptAst, Token[] currentTokens, Int32 fileOffset, IInternalPowerShellExecutionService executionService, ILogger logger, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\Symbols\Visitors\AstOperations.cs:line 141 at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.GetCompletionsInFileAsync(ScriptFile scriptFile, Int32 lineNumber, Int32 columnNumber, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 257 at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.Handle(CompletionParams request, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 91 | [Warn - 4:46:57 PM] Microsoft.PowerShell.EditorServices.Handlers.PsesCodeActionHandler: textDocument/codeAction skipping diagnostic with empty Code field: PowerShell The '<' operator is reserved for future use. | [Warn - 4:47:08 PM] Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler: Exception occurred while running handling completion request - System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.PowerShell.EditorServices.Services.Symbols.AstOperations.GetCompletionsAsync(Ast scriptAst, Token[] currentTokens, Int32 fileOffset, IInternalPowerShellExecutionService executionService, ILogger logger, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\Symbols\Visitors\AstOperations.cs:line 141 at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.GetCompletionsInFileAsync(ScriptFile scriptFile, Int32 lineNumber, Int32 columnNumber, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 257 at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.Handle(CompletionParams request, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 91 | [Warn - 4:47:32 PM] Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler: Exception occurred while running handling completion request - System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.PowerShell.EditorServices.Services.Symbols.AstOperations.GetCompletionsAsync(Ast scriptAst, Token[] currentTokens, Int32 fileOffset, IInternalPowerShellExecutionService executionService, ILogger logger, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\Symbols\Visitors\AstOperations.cs:line 141 at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.GetCompletionsInFileAsync(ScriptFile scriptFile, Int32 lineNumber, Int32 columnNumber, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 257 at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.Handle(CompletionParams request, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 91 | [Warn - 4:47:56 PM] Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler: Exception occurred while running handling completion request - System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.PowerShell.EditorServices.Services.Symbols.AstOperations.GetCompletionsAsync(Ast scriptAst, Token[] currentTokens, Int32 fileOffset, IInternalPowerShellExecutionService executionService, ILogger logger, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\Symbols\Visitors\AstOperations.cs:line 141 at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.GetCompletionsInFileAsync(ScriptFile scriptFile, Int32 lineNumber, Int32 columnNumber, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 257 at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.Handle(CompletionParams request, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 91 |

klawrawkz avatar Mar 27 '23 21:03 klawrawkz

@klawrawkz you have an entirely different issue then the OP of this issue (which is likely resolved because as you noted it was filed two years ago and PSES has gone from v2 to v3 in that time). The OP just didn't come back and re-test and close the issue, so I'll do that for them. I actually since implemented an end-to-end integration test of PSES with Emacs.

If you're using the VS Code extension, please follow the form here for a new bug report.

Thanks!

andyleejordan avatar Mar 27 '23 23:03 andyleejordan

Hell, I don't really care what is causing the exception a this point. So I propose, at the very least, I mean just to get the ball rolling, how about we implement a try-catch that quietly, on the down-low, swallows the exception so it doesn't crash the intellisense in VS code?

@klawrawkz, your suggestion is actually already how the code is written:

https://github.com/PowerShell/PowerShellEditorServices/blob/53f3f1b22d96ecf06e79dd9402e56cb4f564bfe3/src/PowerShellEditorServices/Services/TextDocument/Handlers/CompletionHandler.cs#L85-L90

A try-catch for all exceptions in the completion handler logging the exact message in your stack-trace (repeatedly, because it's not crashing due to that exception).

andyleejordan avatar Mar 27 '23 23:03 andyleejordan

Thanks for the clarification @andschwa. Apologies for misreading the original OP's report. I didn't want to create a duplicate issue, and this looked close enough after a cursory reading. The real issue is that Editor Service blows up when an exception is thrown. It is not handing off an "incomplete completion list." So "what we can't do anything about" crashes the service rendering the Editor Service a useless steaming pile of disorganized bits.

Anyhow, I created a workaround by implementing my own custom POSH Editor Services code, or a hack -- depends on how one views it, that does not crash itself when POSH Editor Services throws an error, even though we can't do anything about completion tasks failing.

Thanks for your quick response and advice. I appreciate it.

klawrawkz avatar Mar 28 '23 22:03 klawrawkz

@klawrawkz can you sure the changes you had to made? Because that exception is getting caught and so shouldn't be what's causing the service to crash. Which makes me think there's an exception happening elsewhere.

andyleejordan avatar Mar 28 '23 23:03 andyleejordan