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

UnexpectedValueException: Expecting a version number in the format x.y #10084

Closed
AndreyMZ opened this issue Aug 3, 2023 · 1 comment · Fixed by #10129
Closed

UnexpectedValueException: Expecting a version number in the format x.y #10084

AndreyMZ opened this issue Aug 3, 2023 · 1 comment · Fixed by #10129
Labels
easy problems Issues that can be fixed without background knowledge of Psalm enhancement Help wanted

Comments

@AndreyMZ
Copy link

AndreyMZ commented Aug 3, 2023

Steps to reproduce

  1. Set phpVersion to "5.1" in the configuration file.
  2. Run Psalm.

Actual result

Uncaught UnexpectedValueException: Expecting a version number in the format x.y in /opt/psalm/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php:1174
Stack trace:
#0 /opt/psalm/vendor/vimeo/psalm/src/Psalm/Internal/CliUtils.php(500): Psalm\Internal\Analyzer\ProjectAnalyzer->setPhpVersion('5.1', 'config')
#1 /opt/psalm/vendor/vimeo/psalm/src/Psalm/Internal/Cli/Psalm.php(349): Psalm\Internal\CliUtils::initPhpVersion(Array, Object(Psalm\Config), Object(Psalm\Internal\Analyzer\ProjectAnalyzer))
#2 /opt/psalm/vendor/vimeo/psalm/psalm(9): Psalm\Internal\Cli\Psalm::run(Array)
#3 /opt/psalm/vendor/bin/psalm(119): include('/opt/psalm/vend...')
#4 {main}
(Psalm 5.11.0@c9b192ab8400fdaf04b2b13d110575adc879aa90 crashed due to an uncaught Throwable)

Expected result

  1. No uncaught exception, no stack trace.
  2. Correct error message telling that PHP 5.1 specified in the configuration file ".xml" is not supported by Psalm, and only PHP 5.4-5.6, 7.0-7.4, 8.0-8.2 are supported.

Root cause

if (!preg_match('/^(5\.[456]|7\.[01234]|8\.[012])(\..*)?$/', $version)) {
throw new UnexpectedValueException('Expecting a version number in the format x.y');
}

Additional information

The error message is also wrong because actually version numbers in the formats x.y.z (e.g. "8.2.8") are also expected.

@weirdan weirdan added enhancement easy problems Issues that can be fixed without background knowledge of Psalm Help wanted labels Aug 3, 2023
@weirdan
Copy link
Collaborator

weirdan commented Aug 3, 2023

Feel free to PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy problems Issues that can be fixed without background knowledge of Psalm enhancement Help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants