Closed rubinlinux closed 8 months ago
Trying to track this down, some interesting items:
1: This is not either call to json_encode inside TreeFetcher.php, I replaced both with a test string, and the outcome is the same
2: without --error-format=json I still see that error, at the end, after all my file-connected errors print out:
...
------ --------------------------------------------------------------------------------------
Line app/libs/utils/states.php
------ --------------------------------------------------------------------------------------
14 Deprecated in PHP 8.0: Required parameter $default follows optional parameter $name.
------ --------------------------------------------------------------------------------------
-- -------------------------------------------------------------------------------------
Error
-- -------------------------------------------------------------------------------------
Child process error (exit code 1): Error: Unable to encode JSON: Recursion detected
-- -------------------------------------------------------------------------------------
So the error is happening somewhere inside phpstan, but only when TreeFetcher is enabled?
However, there are 2 calls to json_encode in TreeFetecher, and neither of them is responsible (as indicated by replacing them with '' strings)
Hey sorry for being a bit slow to respond (am a bit busy). Could it maybe still be related to the TreeFetcher? Maybe PHPStan didn't clear the cache correctly (and just showed you the same error as before) or maybe you edited a different TreeFetcher? Just guessing here since I haven't had a look at the relevant code yet.
Will probably take a look at this coming weekend
Hmm yeah it does sound unlikely that this is coming from the TreeFetcher
since the json_encode
call should just return false
when it fails (it has no JSON_THROW_ON_ERROR
flag). Can you maybe isolate it down to a specific file or piece of code? Maybe by running the command you ran before but checking a single file instead of a folder? Otherwise maybe try disabling the processNode
function in TreeFetcher
(by early-returning). Then it'll effectively do nothing at all, that could provide some clarity.
I already posted to https://github.com/SanderRonde/phpstan-vscode/issues/57#issuecomment-1991337565, but this looks like my problem too. I tried to comment out the json_encode
in TreeFetcher
and nothing changed. It ran without errors and using the cache only after early-returning public function processNode(Node $node, Scope $scope): ?array
as suggested. I've run the generated command with --debug
and it outputted a never ending stream of the same error: Warning: var_export does not handle circular references in phar:///[redacted]/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/ResultCache/ResultCacheManager.php on line 555
Ah that's interesting, so it looks like it fails when serializing it into the resultCache. I've got a couple hunches on what it might be. I've attached a couple of variations of the TreeFetcher
. Could you please try them and report which ones worked and which ones didn't? Depending on how you did the replacing before you might need to change the REPORTER_FILE
back after copying in these files. Thanks in advance!
Sure:
TreeFetcher-no-closure.php
: Never ending stream of var_export does not handle circular references
TreeFetcher-no-collector-processNode.php
: No errorsTreeFetcher-no-data-process.php
: Never ending stream of var_export does not handle circular references
TreeFetcher-no-functions.php
: Never ending stream of var_export does not handle circular references
TreeFetcher-no-process-node.php
: No errorsTreeFetcher-only-functions.php
: No errorsThank you so much for checking it. I'm pretty sure I've found the error. It was the name of a variable being an expression (non-serializable) instead of a string, which I did not expect. I've attached a version of the TreeFetcher that should work. If it does, I'll fix the issue in the extension.
Works :)
Awesome, will add the fix in the next (pre-release) version, 3.0.5
. Thanks again for checking
I'm using the preview release--
Something about the PHPStanVSCodeTreeFetecher is causing phpstan to fail with recursion detected while attempting to output json.
If I copy the command line from the logs, I get something like:
But if I leave out the phpstan-vscode neon file, the error does not happen