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

PHP Notice: Undefined offset => PHP Fatal error: Uncaught UnexpectedValueException: $storage should not be null #2316

Closed
scmrus opened this issue Nov 8, 2019 · 24 comments
Labels

Comments

@scmrus
Copy link

scmrus commented Nov 8, 2019

PHP Notice:  Undefined offset: 2 in /Users/alek/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php on line 927

Notice: Undefined offset: 2 in /Users/alek/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php on line 927
PHP Notice:  Trying to get property 'default' of non-object in /Users/alek/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php on line 930

Notice: Trying to get property 'default' of non-object in /Users/alek/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php on line 930
PHP Fatal error:  Uncaught UnexpectedValueException: $storage should not be null for Packing::getreqaudioformats in /Users/alek/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Methods.php:921
Stack trace:
#0 /Users/alek/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/MethodAnalyzer.php(50): Psalm\Internal\Codebase\Methods->getStorage('Packing::getreq...')
#1 /Users/alek/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(1534): Psalm\Internal\Analyzer\MethodAnalyzer->__construct(Object(PhpParser\Node\Stmt\ClassMethod), Object(Psalm\Internal\Analyzer\ClassAnalyzer))
#2 /Users/alek/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(811): Psalm\Internal\Analyzer\ClassAnalyzer->analyzeClassMethod(Object(PhpParser\Node\Stmt\ClassMethod), Object(Psalm\Storage\ClassLikeStorage), Object(Psalm\Internal\Analyzer\ClassAnalyzer), Object(Psalm\Context), Object(Psalm\Context))
#3 /Users/alek/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FileAnalyzer.php(197): Psalm\ in /Users/alek/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Methods.php on line 921
@scmrus
Copy link
Author

scmrus commented Nov 8, 2019

psalm --version
Psalm 3.6.4@3e98c800ec72e06eed7546956823ff395fc30c75

@muglug
Copy link
Collaborator

muglug commented Nov 8, 2019

Mind running with --debug-by-line to identify the code that causes the failure?

@pilif
Copy link
Contributor

pilif commented Dec 19, 2019

I just ran into the same issue when setting up psalm on a veeeery old branch of ours which was, frankly, a mess.

In my case, this issue was reproducible when:

  • the same class exists multiple times in the same (in my case root) namespace (in reality this wasn't an issue because either file would have been loaded manually)
  • you run psalm with --threads=n where n > 1

This is a race condition where one process sees the class definition and the other sees methods being called on the other class with the same name.

I don't think this needs fixing, but I'm posting here if somebody else runs into the same issue.

@muglug
Copy link
Collaborator

muglug commented Dec 19, 2019

Oh thanks!

@muglug
Copy link
Collaborator

muglug commented Dec 19, 2019

@pilif I’m going to try to reproduce based on this information (but if you can create a small repro repo that would be amazing). At the very least Psalm shouldn’t crash.

@muglug muglug reopened this Dec 19, 2019
@pilif
Copy link
Contributor

pilif commented Dec 19, 2019

I had a lot of trouble reproducing it because it's sheer luck which process sees one class and which sees the usage of the other.

So for various values of n and depending on the machine I was trying on, it would be fine or blow up.

Of the classes in question, both were named Importer, both were abstract, both were subclassed and subclasses of both were checked by psalm.

One of them had a public function startFile($file){} method, the other didn't.

The fix was to exclude the directory containing one of the classes and subclasses.

@leighman
Copy link
Contributor

Also hitting this. Seems like the same problem of different classes with the same name. Would rather not exclude either of the directories. Can psalm disambiguate the files somehow?

@leighman
Copy link
Contributor

leighman commented Feb 20, 2020

3.9 crashes by default for us because of this.
Seem to be able to get around it by setting threads=1 (--init seems to need --debug).

@muglug
Copy link
Collaborator

muglug commented Feb 24, 2020

If anyone can create a repo that reproduces the bug, I'll be able to fix it quickly cc @nickyr

@nickyr
Copy link
Contributor

nickyr commented Feb 28, 2020

Yeah it’s really a struggle to reproduce in a separate repo. And trimming down the problem repo is unwieldy because it’s so big that psalm init eats up all my computer’s application memory If it doesn’t crash first...that’s gonna be an issue.

I’ve seen it fail on two different classes, each of which shares its name with at least one other class. In one case, all the classes with the same name extend the same parent. But in another case, one of the classes has no parents or children.

But making a repo with classes with the same name doesn’t reproduce the issue for me, it just fails with a DuplicateClass error. I wonder if a certain volume of classes is needed for the race condition to have a chance of happening.

@muglug
Copy link
Collaborator

muglug commented Feb 28, 2020

Ahhh - Psalm probably isn’t forking its analysis because the number of files is too low - you can override that in Psalm\Internal\Fork\Pool

Also Nico says hi

@nickyr
Copy link
Contributor

nickyr commented Feb 28, 2020

Ok I got it to fork, had to edit a couple other places. Still no repro though. I may need to think about this whole memory limit issue first anyway...

And hi Nico!

@leighman
Copy link
Contributor

Can now reproduce this on our codebase with --threads=1 too

@muglug
Copy link
Collaborator

muglug commented May 14, 2020

@leighman can you create a reproducer in a new repo?

@leighman
Copy link
Contributor

Can have another go. I have tried in the past and not been able to. I think it has to do with the number of (non-namespaced) files.

@muglug
Copy link
Collaborator

muglug commented May 14, 2020

Right, but if you can reproduce on a single thread it implies an order-of-operations issue that should be reproducible. Another alternative would be to give me temporary access to the repo, but I could understand how that might be complicated.

@zack6849
Copy link

zack6849 commented Aug 4, 2020

I am also getting this, if I run it normally, I get an error about storage and undefined index

If i run with --debug-by-line it never finishes

Stack trace below:

vendor/bin/psalm 16:05:09
Scanning files...
Analyzing files...

zack@hephaestus html (composer)> vendor/bin/psalm                                                                                                                                                                     16:05:09
Scanning files...
Analyzing files...

EEE░EE░EEE░EEEEEEEEEE░EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE  60 / 543 (11%)
░EEEEEE░EEEEEEEEEEE░E░E░EE░PHP Notice:  Undefined offset: 0 in <redacted>/html/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php on line 1119
Notice: Undefined offset: 0 in <redacted>/html/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php on line 1119
PHP Notice:  Trying to get property 'default' of non-object in <redacted>/html/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php on line 1122
Notice: Trying to get property 'default' of non-object in <redacted>/html/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php on line 1122
EUncaught Exception: $storage should not be null for Namespace\Classname::getid
Stack trace in the forked worker:
#0 <redacted>/html/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(1933): Psalm\Internal\Codebase\Methods->getStorage()
#1 <redacted>/html/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(1904): Psalm\Internal\Analyzer\ClassAnalyzer::analyzeClassMethodReturnType()
#2 <redacted>/html/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(739): Psalm\Internal\Analyzer\ClassAnalyzer->analyzeClassMethod()
#3 <redacted>/html/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FileAnalyzer.php(217): Psalm\Internal\Analyzer\ClassAnalyzer->analyze()
#4 <redacted>/html/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(349): Psalm\Internal\Analyzer\FileAnalyzer->analyze()
#5 <redacted>/html/vendor/vimeo/psalm/src/Psalm/Internal/Fork/Pool.php(184): Psalm\Internal\Codebase\Analyzer->Psalm\Internal\Codebase\{closure}()
#6 <redacted>/html/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(415): Psalm\Internal\Fork\Pool->__construct()
#7 <redacted>/html/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(275): Psalm\Internal\Codebase\Analyzer->doAnalysis()
#8 <redacted>/html/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(630): Psalm\Internal\Codebase\Analyzer->analyzeFiles()
#9 <redacted>/html/vendor/vimeo/psalm/src/psalm.php(666): Psalm\Internal\Analyzer\ProjectAnalyzer->check()
#10 <redacted>/html/vendor/vimeo/psalm/psalm(2): require_once('/home/zack/Envi...')
#11 {main} in <redacted>/html/vendor/vimeo/psalm/src/Psalm/Internal/Fork/Pool.php:348
Stack trace:
#0 <redacted>/html/vendor/vimeo/psalm/src/Psalm/Internal/Fork/Pool.php(380): Psalm\Internal\Fork\Pool->readResultsFromChildren()
#1 <redacted>/html/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(481): Psalm\Internal\Fork\Pool->wait()
#2 <redacted>/html/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(275): Psalm\Internal\Codebase\Analyzer->doAnalysis()
#3 <redacted>/html/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(630): Psalm\Internal\Codebase\Analyzer->analyzeFiles()
#4 <redacted>/html/vendor/vimeo/psalm/src/psalm.php(666): Psalm\Internal\Analyzer\ProjectAnalyzer->check()
#5 <redacted>/html/vendor/vimeo/psalm/psalm(2): require_once('/home/zack/Envi...')
#6 {main}
(Psalm 3.13.1@afd8874a9e4562eac42a02de90e42e430c3a1db1 crashed due to an uncaught Throwable)

Obviously redacted the directories and the namespace and class name are changed

Any ideas?

@jgwong
Copy link

jgwong commented Sep 30, 2020

@muglug I've created a repo with which you can reproduce the issue. In my case it happens with Laminas InputFilter library.

Here's the repo: https://github.com/jgwong/psalm-issue-2316-repro

@muglug
Copy link
Collaborator

muglug commented Nov 3, 2020

@jgwong that was a different issue, now fixed.

Closing this as not reproducable

@muglug muglug closed this as completed Nov 3, 2020
@dwasil
Copy link

dwasil commented Feb 27, 2023

I have the similar issue:

> ./tools/psalm --no-cache --no-diff --debug-by-line=1
Uncaught RuntimeException: PHP Error: Undefined property: Psalm\Config::$threads in phar:///Users/********/repos/********/tools/psalm/src/Psalm/Internal/Cli/Psalm.php:604 for command with CLI args "./tools/psalm --no-cache --no-diff --debug-by-line=1" in phar:///Users/********/repos/********/tools/psalm/src/Psalm/Internal/ErrorHandler.php:61
Stack trace:
#0 phar:///Users/********/repos/********/tools/psalm/src/Psalm/Internal/Cli/Psalm.php(604): Psalm\Internal\ErrorHandler::Psalm\Internal\{closure}(2, 'Undefined prope...', 'phar:///Users/v...', 604)
#1 phar:///Users/********/repos/********/tools/psalm/src/Psalm/Internal/Cli/Psalm.php(215): Psalm\Internal\Cli\Psalm::detectThreads(Array, Object(Psalm\Config), false)
#2 phar:///Users/********/repos/********/tools/psalm/psalm(7): Psalm\Internal\Cli\Psalm::run(Array)
#3 /Users/********/repos/********/tools/psalm(14): require('phar:///Users/v...')
#4 {main}
(Psalm 5.7.7@e028ba46ba0d7f9a78bc3201c251e137383e145f crashed due to an uncaught Throwable)
Script ./tools/psalm --no-cache --no-diff --debug-by-line=1 handling the psalm event returned with error code 1

@danog
Copy link
Collaborator

danog commented Feb 27, 2023

Could you please open a new issue @dwasil

@weirdan
Copy link
Collaborator

weirdan commented Feb 27, 2023

Uncaught RuntimeException: PHP Error: Undefined property: Psalm\Config::$threads

It may happen if you also have Psalm installed via composer. Run vendor/bin/psalm instead.

@dwasil
Copy link

dwasil commented Feb 28, 2023

Could you please open a new issue @dwasil

Done. #9423

@dwasil
Copy link

dwasil commented Feb 28, 2023

Uncaught RuntimeException: PHP Error: Undefined property: Psalm\Config::$threads

It may happen if you also have Psalm installed via composer. Run vendor/bin/psalm instead.

It was installed via Phive. Actually, it is just psalm.phar version 5.7.7
After installing via composer it works. But the version is lower than 5.x.

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

No branches or pull requests

10 participants