Skip to content

Gracefully handle missing version constraints#80

Open
jordantrizz wants to merge 1 commit intoaaemnnosttv:masterfrom
jordantrizz:master
Open

Gracefully handle missing version constraints#80
jordantrizz wants to merge 1 commit intoaaemnnosttv:masterfrom
jordantrizz:master

Conversation

@jordantrizz
Copy link

@jordantrizz jordantrizz commented Oct 21, 2025

Issue

In LoginCommand.php endpoint() loads the saved wp_cli_login option and sets $version = isset($saved->version) ? $saved->version : false;.

On older installs that option JSON never had a version field, so $version becomes false.

Passing that value into ServerPlugin::versionSatisfies() ends up calling Semver::satisfies($this->version(), ''), and Composer’s semver parser throws Invalid version string "", which is the fatal you’re seeing.

Fatal error: Uncaught UnexpectedValueException: Could not parse version constraint : Invalid version string "" in phar:///home/localuser/bin/wp/vendor/composer/semver/src/VersionParser.php:526
Stack trace:
#0 phar:///home/localuser/bin/wp/vendor/composer/semver/src/VersionParser.php(281): Composer\Semver\VersionParser->parseConstraint()
#1 phar:///home/localuser/bin/wp/vendor/composer/semver/src/Semver.php(40): Composer\Semver\VersionParser->parseConstraints()
#2 /home/localuser/home/localuser/.wp-cli/packages/vendor/aaemnnosttv/wp-cli-login-command/src/ServerPlugin.php(127): Composer\Semver\Semver::satisfies()
#3 /home/localuser/home/localuser/.wp-cli/packages/vendor/aaemnnosttv/wp-cli-login-command/src/LoginCommand.php(249): WP_CLI_Login\ServerPlugin->versionSatisfies()
#4 /home/localuser/home/localuser/.wp-cli/packages/vendor/aaemnnosttv/wp-cli-login-command/src/LoginCommand.php(420): WP_CLI_Login\LoginCommand->endpoint()
#5 /home/localuser/home/localuser/.wp-cli/packages/vendor/aaemnnosttv/wp-cli-login-command/src/LoginCommand.php(72): WP_CLI_Login\LoginCommand->makeMagicUrl()
#6 [internal function]: WP_CLI_Login\LoginCommand->create()
#7 phar:///home/localuser/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php(100): call_user_func()
#8 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher{closure}()
#9 phar:///home/localuser/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php(497): call_user_func()
#10 phar:///home/localuser/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(470): WP_CLI\Dispatcher\Subcommand->invoke()
#11 phar:///home/localuser/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(493): WP_CLI\Runner->run_command()
#12 phar:///home/localuser/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1295): WP_CLI\Runner->run_command_and_exit()
#13 phar:///home/localuser/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(28): WP_CLI\Runner->start()
#14 phar:///home/localuser/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php(84): WP_CLI\Bootstrap\LaunchRunner->process()
#15 phar:///home/localuser/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php(35): WP_CLI\bootstrap()
#16 phar:///home/localuser/bin/wp/php/boot-phar.php(20): include('...')
#17 /home/localuser/bin/wp(4): include('...')
#18 {main}
thrown in phar:///home/localuser/bin/wp/vendor/composer/semver/src/VersionParser.php on line 526

Resolution

You can delete the stored option by running

wp option delete wp_cli_login

Summary

  • ensure the login server’s version check ignores empty or invalid constraints instead of passing them to Composer\Semver
  • treat missing or malformed plugin versions as “needs update” so older installs flow through the reset path
  • add unit coverage for empty, invalid, and valid constraint scenarios
  • Set plugin version to semver requirements of 1.5.0

Error

Testing

  • vendor/bin/phpunit

@jordantrizz jordantrizz force-pushed the master branch 4 times, most recently from 3efb33a to f656e84 Compare October 22, 2025 17:54
* Gracefully handle missing version constraints.
* Set plugin version to semver requirements 0.0.0
Copy link
Owner

@aaemnnosttv aaemnnosttv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

While you're correct that ServerPlugin->versionSatisfies() will raise an error if called with an invalid version constraint, this should not be possible even going back to the oldest version of the command (1.0).

I see you have also provided a stack trace – are you able to provide steps to reproduce this error consistently using normal wp-cli commands?

$version = is_string($this->version()) ? trim($this->version()) : '';

if ($constraints === '' || $version === '') {
// Saved installs prior to 1.5 did not persist a constraint; force reset flow.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jordantrizz
Copy link
Author

Hello @aaemnnosttv I had a couple of sites that had the mu-plugin and was failing, so I dug deeper and used AI to debug the issue and this is what I was able to find. Since this was October I'd have to see if I left any notes around about this issue. Sorry for the lack of information, I haven't run into the issue again so maybe this was just a one off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants