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
Internal error for which the description of the problem refers to a file that does not do what the error says #6428
Comments
This bug report is missing a link to reproduction on phpstan.org. It will most likely be closed after manual review. |
I managed to find what causing the issue.
When I remove the
I don't really understand why it fails because I use many env var processors in my app but this is one is the first one to fail. |
It is getting weirder and weirder... Here is the service on which PHPStan says it fails: use App\OAuth\OAuthStateDecoderInterface;
use Symfony\Component\Routing\RouterInterface;
class ZoomOAuthAuthenticationFailureHandler implements AuthenticationFailureHandlerInterface
{
public function __construct(
private string $webAppUrl,
private OAuthStateDecoderInterface $stateDecoder,
private RouterInterface $router,
) {
}
// ... rest of the code is omitted
} The definitions: App\OAuth\OAuthStateDecoder:
arguments:
$secret: "%env(string:APP_SECRET)%"
$ttl: "%env(int:OAUTH_STATE_TTL)%"
App\OAuth\OAuthStateDecoderInterface: '@App\OAuth\OAuthStateDecoder'
App\Security\Authenticator\Handler\ZoomOAuthAuthenticationFailureHandler:
arguments:
$webAppUrl: "%env(string:WEB_APP_FRONTEND_URL)%" Here is what I tried:
So in the end I am not sure anymore it is linked to the env var processors. I don't find a simple way to debug that, how could I add breakpoints and use Xdebug in sub processes? |
And problem found! It was due to the fact that my code was try/catching an exception without assigning the exception to a value. /**
* @return array<string, mixed>
*/
private function decodeState(?string $state): array
{
if (null === $state) {
return [];
}
try {
return $this->stateDecoder->decode($state, false);
} catch (InvalidOAuthStateException) { // <- $e is missing, on purpose as it is not used afterward.
return [];
}
} I finally managed to have the stack trace of the error, but it only led me on the way and it is linked to thecodingmachine/phpstan-strict-rules#57 #0 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/src/Analyser/FileAnalyser.php(94):
TheCodingMachine\PHPStan\Rules\Exceptions\ThrowMustBundlePreviousExceptionRule->processNode(Object(PhpParser\Node\Stmt\Catch_), Object(PHPStan\Analyser\MutatingScope))
#1 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/src/Node/ClassStatementsGatherer.php(95):
PHPStan\Analyser\FileAnalyser->PHPStan\Analyser\{closure}(Object(PhpParser\Node\Stmt\Catch_), Object(PHPStan\Analyser\MutatingScope))
#2 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/src/Analyser/NodeScopeResolver.php(445): PHPStan\Node\ClassStatementsGatherer->__invoke(Object(PhpParser\Node\Stmt\Catch_),
Object(PHPStan\Analyser\MutatingScope))
#3 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/src/Analyser/NodeScopeResolver.php(1001):
PHPStan\Analyser\NodeScopeResolver::PHPStan\Analyser\{closure}(Object(PhpParser\Node\Stmt\Catch_), Object(PHPStan\Analyser\MutatingScope))
#4 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/src/Analyser/NodeScopeResolver.php(298): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\TryCatch),
Object(PHPStan\Analyser\MutatingScope), Object(Closure))
#5 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/src/Analyser/NodeScopeResolver.php(460):
PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\ClassMethod), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure))
#6 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/src/Analyser/NodeScopeResolver.php(298): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\ClassMethod),
Object(PHPStan\Analyser\MutatingScope), Object(PHPStan\Node\ClassStatementsGatherer))
#7 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/src/Analyser/NodeScopeResolver.php(544): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Class_),
Array, Object(PHPStan\Analyser\MutatingScope), Object(PHPStan\Node\ClassStatementsGatherer))
#8 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/src/Analyser/NodeScopeResolver.php(298): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Class_),
Object(PHPStan\Analyser\MutatingScope), Object(Closure))
#9 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/src/Analyser/NodeScopeResolver.php(510): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Namespace_),
Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure))
#10 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/src/Analyser/NodeScopeResolver.php(269): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Namespace_),
Object(PHPStan\Analyser\MutatingScope), Object(Closure))
#11 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/src/Analyser/FileAnalyser.php(181): PHPStan\Analyser\NodeScopeResolver->processNodes(Array, Object(PHPStan\Analyser\MutatingScope),
Object(Closure))
#12 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/src/Command/WorkerCommand.php(143): PHPStan\Analyser\FileAnalyser->analyseFile('/Users/benjamin...', Array,
Object(PHPStan\Rules\Registry), NULL)
#13 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97): PHPStan\Command\WorkerCommand->PHPStan\Command\{closure}(Array)
#14 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/vendor/clue/ndjson-react/src/Decoder.php(110): _PHPStan_1aef99d3c\Evenement\EventEmitter->emit('data', Array)
#15 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97): _PHPStan_1aef99d3c\Clue\React\NDJson\Decoder->handleData(Array)
#16 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/vendor/react/stream/src/Util.php(62): _PHPStan_1aef99d3c\Evenement\EventEmitter->emit('data', Array)
#17 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97):
_PHPStan_1aef99d3c\React\Stream\Util::_PHPStan_1aef99d3c\React\Stream\{closure}('{"action":"anal...')
#18 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/vendor/react/stream/src/DuplexResourceStream.php(154): _PHPStan_1aef99d3c\Evenement\EventEmitter->emit('data', Array)
#19 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(200): _PHPStan_1aef99d3c\React\Stream\DuplexResourceStream->handleData(Resource id
#3625)
#20 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(172):
_PHPStan_1aef99d3c\React\EventLoop\StreamSelectLoop->waitForStreamActivity(NULL)
#21 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/src/Command/WorkerCommand.php(106): _PHPStan_1aef99d3c\React\EventLoop\StreamSelectLoop->run()
#22 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/vendor/symfony/console/Command/Command.php(259):
PHPStan\Command\WorkerCommand->execute(Object(_PHPStan_1aef99d3c\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_1aef99d3c\Symfony\Component\Console\Output\ConsoleOutput))
#23 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/vendor/symfony/console/Application.php(848):
_PHPStan_1aef99d3c\Symfony\Component\Console\Command\Command->run(Object(_PHPStan_1aef99d3c\Symfony\Component\Console\Input\ArgvInput),
Object(_PHPStan_1aef99d3c\Symfony\Component\Console\Output\ConsoleOutput))
#24 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/vendor/symfony/console/Application.php(259):
_PHPStan_1aef99d3c\Symfony\Component\Console\Application->doRunCommand(Object(PHPStan\Command\WorkerCommand), Object(_PHPStan_1aef99d3c\Symfony\Component\Console\Input\ArgvInput),
Object(_PHPStan_1aef99d3c\Symfony\Component\Console\Output\ConsoleOutput))
#25 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/vendor/symfony/console/Application.php(157):
_PHPStan_1aef99d3c\Symfony\Component\Console\Application->doRun(Object(_PHPStan_1aef99d3c\Symfony\Component\Console\Input\ArgvInput),
Object(_PHPStan_1aef99d3c\Symfony\Component\Console\Output\ConsoleOutput))
#26 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/bin/phpstan(94): _PHPStan_1aef99d3c\Symfony\Component\Console\Application->run()
#27 phar:///Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar/bin/phpstan(95): _PHPStan_1aef99d3c\{closure}()
#28 /Users/benjamingrandfond/Dev/phpstan-src/tmp/phpstan.phar(6): require('phar:///Users/b...')
#29 {main} |
Sorry for the noise here! Even if I found my problem, I think there might still be some issues here: The output does not help to fully understand the internal error It is quite cumbersome to debug what is happening in a worker
And there still some open questions
I'd be glad to help but I have no idea from where to look at, yet. |
No idea, probably some confusion about the internal error.
Because the problem is probably related to some non-deterministic and side-effect nature of why the error sometimes appears and sometimes not. This is usually because the error doesn't happen when something is executed before the important part of the code that causes it. With a single thread all the things always happen in the same order, but with parallelization, there are differences and the order of executed lines of code can change and that's why your error sometimes appears and sometimes not. One of the notable examples of this is twigphp/Twig#3562. The function So if you're lucky and PHPStan analyses code that uses Your problem will probably be similar, something about lazy initialization etc... |
Latest PHPStan version should show you the error with stack trace in CI if you run with |
@ondrejmirtes the stack trace is the one I here in this issue. It helped me to fix the error I had when reporting the issue. However, there are still some issues for which I wasn't able to debug so far. Anyway, if they are not reported again then maybe it is not worth keeping the issue open. :) |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug report
Hi 👋🏻,
tl;dr: problem solved bug it might be some issue underlying, see my last comment
I am sorry for the long and unprecise title, I don't really know how to describe the issue in one sentence...
PHPStan fails in our CI with the following error:
I tried to reproduce it locally but I can't, PHPStan succeeds.
edit: I cleared PHPStan's cache and now it fails but does not with the
--debug
flag.I tried to run the command on the container in the CI via SSH, it fails with the sameerror as expected. Then I tried to add the
--debug
flag and this time it succeeds. I tried again without the flag, it still fails. I removed the cache and tried again, it still fails.What I don't understand is that there is no call to a "name" property in this file. So maybe it is rather PHPStan that raises the error internally when analyzing this file.
Code snippet that reproduces the problem
I don't have any way to reproduce it locally, I don't understand the issue enough, I am sorry.
Expected output
I expected to not have error on every environment.
Did PHPStan help you today? Did it make you happy in any way?
Ooooh yes! It does a lot. Thank you so much for building it 🙏🏻
The text was updated successfully, but these errors were encountered: