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 Fatal error: Uncaught UnexpectedValueException: Expecting strval to have storage #1200

Closed
coderintherye opened this issue Jan 14, 2019 · 23 comments
Labels

Comments

@coderintherye
Copy link

Below is what happens when running from the command line as shown

$ ./vendor/bin/psalm --use-ini-defaults --threads=4
Scanning files...
Analyzing files...
Child terminated without returning a serialized array - response type=boolean
Child terminated without returning a serialized array - response type=boolean
Child terminated without returning a serialized array - response type=boolean
PHP Fatal error: Uncaught TypeError: Argument 1 passed to Psalm\IssueBuffer::addIssues() must be of the type array, null given, called in /kiva/main/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php on line 252 and defined in /kiva/main/vendor/vimeo/psalm/src/Psalm/IssueBuffer.php:215
Stack trace:
#0 /kiva/main/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(252): Psalm\IssueBuffer::addIssues(NULL)
#1 /kiva/main/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(416): Psalm\Internal\Codebase\Analyzer->analyzeFiles(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 4, false)
#2 /kiva/main/vendor/vimeo/psalm/src/psalm.php(501): Psalm\Internal\Analyzer\ProjectAnalyzer->check('/kiva/main/', false)
#3 /kiva/main/vendor/vimeo/psalm/psalm(2): require_once('/kiva/main/vend...')
#4 {main}
thrown in /kiva/main/vendor/vimeo/psalm/src/Psalm/IssueBuffer.php on line 215
Fatal error: Uncaught TypeError: Argument 1 passed to Psalm\IssueBuffer::addIssues() must be of the type array, null given, called in /kiva/main/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php on line 252 and defined in /kiva/main/vendor/vimeo/psalm/src/Psalm/IssueBuffer.php:215
Stack trace:
#0 /kiva/main/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(252): Psalm\IssueBuffer::addIssues(NULL)
#1 /kiva/main/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(416): Psalm\Internal\Codebase\Analyzer->analyzeFiles(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 4, false)
#2 /kiva/main/vendor/vimeo/psalm/src/psalm.php(501): Psalm\Internal\Analyzer\ProjectAnalyzer->check('/kiva/main/', false)
#3 /kiva/main/vendor/vimeo/psalm/psalm(2): require_once('/kiva/main/vend...')
#4 {main}
thrown in /kiva/main/vendor/vimeo/psalm/src/Psalm/IssueBuffer.php on line 215

@muglug
Copy link
Collaborator

muglug commented Jan 14, 2019

What happens when you run it without --threads?

@coderintherye
Copy link
Author

Different error at least then:
$ ./vendor/bin/psalm --use-ini-defaults
Scanning files...
Analyzing files...
PHP Fatal error: Uncaught UnexpectedValueException: Expecting strval to have storage in ...

I'll try further with excluding the directory that error arose in

@muglug
Copy link
Collaborator

muglug commented Jan 14, 2019

ah hold up, would you mind running ./vendor/bin/psalm --use-ini-defaults --debug-by-line to find the exact place Psalm gave up? Then I should be able to fix very quickly.

@muglug muglug added the bug label Jan 14, 2019
@coderintherye
Copy link
Author

Ok, here it is back with 4 threads and adding the debug by line
...
Analyzing /kiva/main/scripts/kiva_core_generator/kc_object.template.php
/kiva/main/scripts/kiva_core_generator/kc_object.template.php:2
Child terminated without returning a serialized array - response type=boolean
Child terminated without returning a serialized array - response type=boolean
Child terminated without returning a serialized array - response type=boolean
PHP Fatal error: Uncaught TypeError: Argument 1 passed to Psalm\IssueBuffer::addIssues() must be of the type array, null given, called in /kiva/main/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php on line 252 and defined in /kiva/main/vendor/vimeo/psalm/src/Psalm/IssueBuffer.php:215
Stack trace:
#0 /kiva/main/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(252): Psalm\IssueBuffer::addIssues(NULL)
#1 /kiva/main/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(416): Psalm\Internal\Codebase\Analyzer->analyzeFiles(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 4, false)
#2 /kiva/main/vendor/vimeo/psalm/src/psalm.php(501): Psalm\Internal\Analyzer\ProjectAnalyzer->check('/kiva/main/', false)
#3 /kiva/main/vendor/vimeo/psalm/psalm(2): require_once('/kiva/main/vend...')
#4 {main}
thrown in /kiva/main/vendor/vimeo/psalm/src/Psalm/IssueBuffer.php on line 215
Fatal error: Uncaught TypeError: Argument 1 passed to Psalm\IssueBuffer::addIssues() must be of the type array, null given, called in /kiva/main/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php on line 252 and defined in /kiva/main/vendor/vimeo/psalm/src/Psalm/IssueBuffer.php:215
Stack trace:
#0 /kiva/main/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(252): Psalm\IssueBuffer::addIssues(NULL)
#1 /kiva/main/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(416): Psalm\Internal\Codebase\Analyzer->analyzeFiles(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 4, false)
#2 /kiva/main/vendor/vimeo/psalm/src/psalm.php(501): Psalm\Internal\Analyzer\ProjectAnalyzer->check('/kiva/main/', false)
#3 /kiva/main/vendor/vimeo/psalm/psalm(2): require_once('/kiva/main/vend...')
#4 {main}
thrown in /kiva/main/vendor/vimeo/psalm/src/Psalm/IssueBuffer.php on line 215

@muglug
Copy link
Collaborator

muglug commented Jan 14, 2019

The debug-by-line output won't be as useful when running with threads, so better to turn those off. Psalm is emitting a fatal error in any case, and that's causing threaded execution to fail in a big way.

Would you mind rerunning with --debug-by-line --no-cache (to make sure it's not a cache-related issue)?

Also what happens on line 2 of kc_object.template.php? Could you paste (or describe) that code?

@coderintherye
Copy link
Author

coderintherye commented Jan 14, 2019

@muglug Yes, good point, that code is perhaps not something that works well with the analyzer, the whole file is basically as is noted here:
https://gist.github.com/coderintherye/24e0e31d2754fd7e9de44d6175b5e66d

(moved to gist cause github comments filter out the php tags)

@muglug
Copy link
Collaborator

muglug commented Jan 14, 2019

To clarify, when you run --debug-by-line --no-cache (with no threading) you just get those lines of output (after scanning is done)?

Analyzing /kiva/main/scripts/kiva_core_generator/kc_object.template.php
/kiva/main/scripts/kiva_core_generator/kc_object.template.php:2

@muglug
Copy link
Collaborator

muglug commented Jan 14, 2019

The PHP error traceback should at least give some indication of what's causing the bug in Psalm.

@coderintherye
Copy link
Author

@muglug No sorry I truncated of just grabbing the last few lines, it basically prints out all the lines as it scans and analyzes, it's just that was the one where it threw the error. Would you want the full output from the entire scan? It's quite large as I believe there's a few thousand files so likely would need to upload it for you. Do you have enough info from the error + the lines noted in the output? I could try to create a test repo with just the offending file to see if that gives the same error

@muglug
Copy link
Collaborator

muglug commented Jan 15, 2019

Sadly the snippet you gave (a standard variable assignment to a string) isn’t the root cause. You should hopefully have a longer error output that resembles something like the one given in #1026?

@muglug
Copy link
Collaborator

muglug commented Jan 15, 2019

Obviously if you can narrow it down yourself that’d be great, too, but I don’t want to make you do my work for me :)

@muglug muglug changed the title Argument 1 passed to Psalm\IssueBuffer::addIssues() must be of the type array, null given PHP Fatal error: Uncaught UnexpectedValueException: Expecting strval to have storage Jan 15, 2019
@muglug
Copy link
Collaborator

muglug commented Jan 15, 2019

Also the message "PHP Fatal error: Uncaught UnexpectedValueException: Expecting strval to have storage in..." should be followed by a filename - is there a reference to strval in that file and if so, where?

@coderintherye
Copy link
Author

@muglug note I was able to get a successful run by excluding a few of the directories and not adding threads=4. Passing the threads option, the results seem to be non-deterministic. I'll see if I can narrow down out of the excluded directories by adding them back in and then reporting back on the files with outputs that fatal errored

@muglug
Copy link
Collaborator

muglug commented Jan 15, 2019

To help narrow down, you can run Psalm on those directories directly by running vendor/bin/psalm <directory_name>

@coderintherye
Copy link
Author

@muglug here's one with the full output that failed, run on some library code (which I had since excluded) but as you can see it reproduces the behavior
https://gist.github.com/coderintherye/fe2541fcdd8e6826d03993d6cdebcf65

@coderintherye
Copy link
Author

@muglug also those lines are
line 57 case 'selected':
line 58 $$_key = array_map('strval', array_values((array)$_val));
line 59 break;

@muglug
Copy link
Collaborator

muglug commented Jan 15, 2019

Great, I can reproduce with this clone of smarty: opensolutions/smarty@8466966

Temp workaround: use an autoloader (autoloader="some_file.php" in your psalm.xml) with the following:

<?php
define('SMARTY_PLUGINS_DIR', 'plugins/');
define('SMARTY_SYSPLUGINS_DIR', 'sysplugins/');
define('DS', '/');

@muglug muglug closed this as completed in 8d61cb4 Jan 15, 2019
@muglug
Copy link
Collaborator

muglug commented Jan 15, 2019

Thanks for the digging - when Psalm encounters a require path it can’t resolve it stops checking functions calls. The bug here was that it nevertheless checked implicit function calls in array_map/array_filter.

The workaround above helps Psalm figure out what the require should be, and the actual bugfix tells Psalm to stop analysis of the array_map/array_filter functions if check_functions has been turned off by the engine.

@coderintherye
Copy link
Author

@muglug Thanks so much for being such a responsive and dedicated maintainer of this project. Psalm seems great and we're hoping to set it up for continual use at Kiva.org

@muglug
Copy link
Collaborator

muglug commented Jan 15, 2019

You're welcome! Thanks for working to do good in the world!

@bkdotcom
Copy link
Contributor

Similar (same?) issue:

PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'Expecting .../Config.php:38:782:-:closure to have storage in .../Config.php' in .../vendor/vimeo/psalm/src/Psalm/Codebase.php:403
Stack trace:
#0 .../vendor/vimeo/psalm/src/Psalm/Checker/FunctionLikeChecker.php(234): Psalm\Codebase->getClosureStorage('/Users/bkent/Dr...', '/Users/bkent/Dr...')
#1 .../vendor/vimeo/psalm/src/Psalm/Checker/Statements/ExpressionChecker.php(344): Psalm\Checker\FunctionLikeChecker->analyze(Object(Psalm\Context), Object(Psalm\Context))
#2 .../vendor/vimeo/psalm/src/Psalm/Checker/Statements/Expression/AssignmentChecker.php(122): Psalm\Checker\Statements\Expression in .../vendor/vimeo/psalm/src/Psalm/Codebase.php on line 403

@muglug
Copy link
Collaborator

muglug commented Oct 20, 2019

Would you mind opening a new issue for that? Very likely a different issue

@bkdotcom
Copy link
Contributor

#2250

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

3 participants