psalm: Uncaught Exception: $storage should not be null
Getting the following exception while scanning a huge project with multiple threads enabled.
Uncaught Exception: $storage should not be null for Module\Comment\Orm\MarkFakeMapper::getkey
Stack trace in the forked worker:
#0 /root/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(2038): Psalm\Internal\Codebase\Methods->getStorage()
#1 /root/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(2009): Psalm\Internal\Analyzer\ClassAnalyzer::analyzeClassMethodReturnType()
#2 /root/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(758): Psalm\Internal\Analyzer\ClassAnalyzer->analyzeClassMethod()
#3 /root/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FileAnalyzer.php(210): Psalm\Internal\Analyzer\ClassAnalyzer->analyze()
#4 /root/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(340): Psalm\Internal\Analyzer\FileAnalyzer->analyze()
#5 /root/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Fork/Pool.php(193): Psalm\Internal\Codebase\Analyzer->Psalm\Internal\Codebase\{closure}()
#6 /root/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(406): Psalm\Internal\Fork\Pool->__construct()
#7 /root/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(269): Psalm\Internal\Codebase\Analyzer->doAnalysis()
#8 /root/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(639): Psalm\Internal\Codebase\Analyzer->analyzeFiles()
#9 /root/.composer/vendor/vimeo/psalm/src/psalm.php(676): Psalm\Internal\Analyzer\ProjectAnalyzer->check()
#10 /root/.composer/vendor/vimeo/psalm/psalm(2): require_once('/root/.composer...')
#11 {main} in /root/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Fork/Pool.php:357
Stack trace:
#0 /root/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Fork/Pool.php(389): Psalm\Internal\Fork\Pool->readResultsFromChildren()
#1 /root/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(473): Psalm\Internal\Fork\Pool->wait()
#2 /root/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(269): Psalm\Internal\Codebase\Analyzer->doAnalysis()
#3 /root/.composer/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(639): Psalm\Internal\Codebase\Analyzer->analyzeFiles()
#4 /root/.composer/vendor/vimeo/psalm/src/psalm.php(676): Psalm\Internal\Analyzer\ProjectAnalyzer->check()
#5 /root/.composer/vendor/vimeo/psalm/psalm(2): require_once('/root/.composer...')
#6 {main}
(Psalm dev-master@3b6550f892b97039bcdca0bd44f89c791da0c883 crashed due to an uncaught Throwable)
This is caused by the fact that Module\Comment\Orm\MarkFakeMapper class is present in two different files: the full version with the getKey is autoloaded normally from a PSR-4 path, while a stub version (with no methods) is conditionally included in another place of the code.
Indeed, the MarkFakeMapper ClassStorage is created twice, in two different threads.
In the first one, the full class is scanned and the class storage is populated with the the MethodStorage associated with Module\Comment\Orm\MarkFakeMapper::getkey
.
In another thread, the stub class is scanned instead, causing an error while fetching the MethodStorage associated with getkey later on in the code.
I can (and will) blacklist the stubs from scanning, but it would be nice if psalm could nicely handle such conditions, instead of throwing a weird error 😃
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 3
- Comments: 17 (3 by maintainers)
Similar behaviour for me on a very big project with legacy code. I was unable to complete init step. At the end with --debug the step was done. Unfortunately I cannot proceed with normal usage (vendor/bin/psalm) I’ve tried all the options I know (–debug, --threads=?, --memory-limit ) but i’m not able to execute normal analysis.
Psalm 5.4.0@62db5d4f6a7ae0a20f7cc5a4952d730272fc0863 PHP 8.1.2