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

Psalm Breaks On Syntax Error #142

Closed
PythooonUser opened this issue Jan 12, 2022 · 5 comments
Closed

Psalm Breaks On Syntax Error #142

PythooonUser opened this issue Jan 12, 2022 · 5 comments

Comments

@PythooonUser
Copy link

Summary

The psalm extension breaks when there is a syntax error (e.g. missing closing }).

Steps to Reproduce

  • Create new Symfony project using $ symfony new .
  • Optional: Install maker-bundle in order to create Controller stub using $ composer require --dev maker, $ composer require doctrine/annotations, $ php bin/console make:controller GrumpyPopsicleController

The generated class looks as follows:

<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class GrumpyPopsicleController extends AbstractController
{
    #[Route('/grumpy/popsicle', name: 'grumpy_popsicle')]
    public function index(): Response
    {
        return $this->json([
            'message' => 'Welcome to your new controller!',
            'path' => 'src/Controller/GrumpyPopsicleController.php',
        ]);
    }
}
  • Remove the closing } on the second to last row, matching the GrumpyPopsicleController::index method.
  • Save, for Psalm to update state
  • Psalm reports an error on the last line, Unclosed '{' on line 10
  • Re-add the } token, save, remove it again, save.
  • Hover again over the error message, which now includes a second one: Syntax error, unexpected EOF on line 20 (Psalmhttps://psalm.dev/173) and Unclosed '{' on line 10
  • This time, an error is spawned in the console
[Error] Request textDocument/codeAction failed.
  Message: InvalidArgumentException: Could not get class storage for app\controller\grumpypopsiclecontroller in /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Provider/ClassLikeStorageProvider.php:46
Stack trace:
#0 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php(109): Psalm\Internal\Provider\ClassLikeStorageProvider->get()
#1 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(128): Psalm\Internal\Analyzer\ClassLikeAnalyzer->__construct()
#2 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/NamespaceAnalyzer.php(112): Psalm\Internal\Analyzer\ClassAnalyzer->__construct()
#3 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/NamespaceAnalyzer.php(70): Psalm\Internal\Analyzer\NamespaceAnalyzer->collectAnalyzableClassLike()
#4 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FileAnalyzer.php(314): Psalm\Internal\Analyzer\NamespaceAnalyzer->collectAnalyzableInformation()
#5 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FileAnalyzer.php(193): Psalm\Internal\Analyzer\FileAnalyzer->populateCheckers()
#6 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(362): Psalm\Internal\Analyzer\FileAnalyzer->analyze()
#7 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(619): Psalm\Internal\Codebase\Analyzer->Psalm\Internal\Codebase\{closure}()
#8 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(291): Psalm\Internal\Codebase\Analyzer->doAnalysis()
#9 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/LanguageServer/Server/TextDocument.php(368): Psalm\Internal\Codebase\Analyzer->analyzeFiles()
#10 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/felixfbecker/advanced-json-rpc/lib/Dispatcher.php(168): Psalm\Internal\LanguageServer\Server\TextDocument->codeAction()
#11 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/LanguageServer/LanguageServer.php(152): AdvancedJsonRpc\Dispatcher->dispatch()
#12 [internal function]: Psalm\Internal\LanguageServer\LanguageServer->Psalm\Internal\LanguageServer\{closure}()
#13 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/amphp/amp/lib/Coroutine.php(67): Generator->current()
#14 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/amphp/amp/lib/functions.php(96): Amp\Coroutine->__construct()
#15 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/amphp/amp/lib/functions.php(61): Amp\call()
#16 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/LanguageServer/EmitterTrait.php(84): Amp\{closure}()
#17 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/LanguageServer/ProtocolStreamReader.php(118): Psalm\Internal\LanguageServer\ProtocolStreamReader->emit()
#18 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/LanguageServer/ProtocolStreamReader.php(67): Psalm\Internal\LanguageServer\ProtocolStreamReader->readMessages()
#19 [internal function]: Psalm\Internal\LanguageServer\ProtocolStreamReader->Psalm\Internal\LanguageServer\{closure}()
#20 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/amphp/amp/lib/Coroutine.php(118): Generator->send()
#21 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/amphp/amp/lib/Internal/Placeholder.php(149): Amp\Coroutine->Amp\{closure}()
#22 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/amphp/amp/lib/Deferred.php(53): Amp\Promise@anonymous->resolve()
#23 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/amphp/byte-stream/lib/ResourceInputStream.php(101): Amp\Deferred->resolve()
#24 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/amphp/amp/lib/Loop/NativeDriver.php(327): Amp\ByteStream\ResourceInputStream::Amp\ByteStream\{closure}()
#25 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/amphp/amp/lib/Loop/NativeDriver.php(127): Amp\Loop\NativeDriver->selectStreams()
#26 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/amphp/amp/lib/Loop/Driver.php(138): Amp\Loop\NativeDriver->dispatch()
#27 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/amphp/amp/lib/Loop/Driver.php(72): Amp\Loop\Driver->tick()
#28 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/amphp/amp/lib/Loop.php(95): Amp\Loop\Driver->run()
#29 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(554): Amp\Loop::run()
#30 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Cli/LanguageServer.php(321): Psalm\Internal\Analyzer\ProjectAnalyzer->server()
#31 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/psalm-language-server(7): Psalm\Internal\Cli\LanguageServer::run()
#32 {main}
  Code: -32603
  • Now add back the } brace
  • The psalm extension will crash because of too many failures, and the logs show:
[ERROR] Uncaught InvalidArgumentException: Could not get class storage for app\controller\grumpypopsiclecontroller in /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Provider/ClassLikeStorageProvider.php:46
Stack trace:
#0 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php(109): Psalm\Internal\Provider\ClassLikeStorageProvider->get()
#1 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(128): Psalm\Internal\Analyzer\ClassLikeAnalyzer->__construct()
#2 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/NamespaceAnalyzer.php(112): Psalm\Internal\Analyzer\ClassAnalyzer->__construct()
#3 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/NamespaceAnalyzer.php(70): Psalm\Internal\Analyzer\NamespaceAnalyzer->collectAnalyzableClassLike()
#4 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FileAnalyzer.php(314): Psalm\Internal\Analyzer\NamespaceAnalyzer->collectAnalyzableInformation()
#5 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FileAnalyzer.php(193): Psalm\Internal\Analyzer\FileAnalyzer->populateCheckers()
#6 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(362): Psalm\Internal\Analyzer\FileAnalyzer->analyze()
#7 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(619): Psalm\Internal\Codebase\Analyzer->Psalm\Internal\Codebase\{closure}()
#8 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(291): Psalm\Internal\Codebase\Analyzer->doAnalysis()
#9 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/LanguageServer/LanguageServer.php(349): Psalm\Internal\Codebase\Analyzer->analyzeFiles()
#10 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/LanguageServer/LanguageServer.php(188): Psalm\Internal\LanguageServer\LanguageServer->doAnalysis()
#11 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/LanguageServer/EmitterTrait.php(84): Psalm\Internal\LanguageServer\LanguageServer->Psalm\Internal\LanguageServer\{closure}()
#12 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/LanguageServer/ProtocolStreamReader.php(68): Psalm\Internal\LanguageServer\ProtocolStreamReader->emit()
#13 [internal function]: Psalm\Internal\LanguageServer\ProtocolStreamReader->Psalm\Internal\LanguageServer\{closure}()
#14 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/amphp/amp/lib/Coroutine.php(118): Generator->send()
#15 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/amphp/amp/lib/Internal/Placeholder.php(149): Amp\Coroutine->Amp\{closure}()
#16 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/amphp/amp/lib/Deferred.php(53): Amp\Promise@anonymous->resolve()
#17 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/amphp/byte-stream/lib/ResourceInputStream.php(109): Amp\Deferred->resolve()
#18 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/amphp/amp/lib/Loop/Driver.php(119): Amp\ByteStream\ResourceInputStream::Amp\ByteStream\{closure}()
#19 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/amphp/amp/lib/Loop/Driver.php(72): Amp\Loop\Driver->tick()
#20 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/amphp/amp/lib/Loop.php(95): Amp\Loop\Driver->run()
#21 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(554): Amp\Loop::run()
#22 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/src/Psalm/Internal/Cli/LanguageServer.php(321): Psalm\Internal\Analyzer\ProjectAnalyzer->server()
#23 /home/felix/Documents/Projects/psalm-vscode-plugin-test/vendor/vimeo/psalm/psalm-language-server(7): Psalm\Internal\Cli\LanguageServer::run()
#24 {main}
(Psalm 4.18.1@dda05fa913f4dc6eb3386f2f7ce5a45d37a71bcb crashed due to an uncaught Throwable)
[Error] Connection to server got closed. Server will not be restarted.
[Error] Request textDocument/codeAction failed.
Error: Connection got disposed.
	at Object.dispose (/home/felix/Documents/Projects/psalm-vscode-plugin/dist/extension.js:9865:27)
	at Object.dispose (/home/felix/Documents/Projects/psalm-vscode-plugin/dist/extension.js:12064:35)
	at LanguageClient.handleConnectionClosed (/home/felix/Documents/Projects/psalm-vscode-plugin/dist/extension.js:14415:42)
	at LanguageClient.handleConnectionClosed (/home/felix/Documents/Projects/psalm-vscode-plugin/dist/extension.js:18285:15)
	at closeHandler (/home/felix/Documents/Projects/psalm-vscode-plugin/dist/extension.js:14402:18)
	at CallbackList.invoke (/home/felix/Documents/Projects/psalm-vscode-plugin/dist/extension.js:10001:39)
	at Emitter.fire (/home/felix/Documents/Projects/psalm-vscode-plugin/dist/extension.js:10063:36)
	at closeHandler (/home/felix/Documents/Projects/psalm-vscode-plugin/dist/extension.js:9077:26)
	at CallbackList.invoke (/home/felix/Documents/Projects/psalm-vscode-plugin/dist/extension.js:10001:39)
	at Emitter.fire (/home/felix/Documents/Projects/psalm-vscode-plugin/dist/extension.js:10063:36)
	at StreamMessageReader.fireClose (/home/felix/Documents/Projects/psalm-vscode-plugin/dist/extension.js:10747:27)
	at Socket.<anonymous> (/home/felix/Documents/Projects/psalm-vscode-plugin/dist/extension.js:10832:42)
	at Socket.emit (events.js:327:22)
	at Pipe.<anonymous> (net.js:673:12)
	at Pipe.callbackTrampoline (internal/async_hooks.js:131:14)

Interestingly, after Psalm crashed, you can still add/remove the } and save accordingly, and the original error message is shown/hidden. Unclosed '{' on line 10.

@tm1000
Copy link
Collaborator

tm1000 commented Jan 12, 2022

Thanks for the report.

This is actually an error with upstream vimeo/psalm so you'd need to report the error there in the future. This project merely interfaces with Vimeo/psalm.

Regardless it's already been fixed as of two days ago (by me). It just hasn't been released yet.

@tm1000 tm1000 closed this as completed Jan 12, 2022
@tm1000
Copy link
Collaborator

tm1000 commented Jan 12, 2022

Ref: vimeo/psalm#7368

@PythooonUser
Copy link
Author

Hey 👋

Thanks for the heads-up!

I wonder about the last part of the error logs. [Error] Connection to server got closed. Server will not be restarted.

It seems that the extension does not gracefully exits when VS Code crashes/deactivates it? Could, of course, be a VS Code issue again. I see a lot of callbacks in the stack trace.

@tm1000
Copy link
Collaborator

tm1000 commented Jan 12, 2022

In vscode main after a language server crashes more than 5 times in the span of 3 minutes then vscode will abort the running of the extension. This is to protect the stability of vscode and the host system

I've been trying to go through psalms language server and just try catching most places where this crashes because in the end the language server should almost never crash

@PythooonUser
Copy link
Author

With the next version of Psalm then hopefully even less :) Thanks for fixing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants