wp plugin update fails badly on unparsable tags
Bug Report
- [x] Yes, I reviewed the contribution guidelines.
- [x] Yes, more specifically, I reviewed the guidelines on how to write clear bug reports.
Describe the current, buggy behavior
wp plugin update fails badly if a repository provide unparsable tags.
Describe how other contributors can replicate this bug
- Install
wp-maintenance-mode2.2.x (It's important to be below the maximum release. 2.2.4 for example) - Run
wp @ae plugin update --patch wp-maintenance-mode - Encounter an error
Uncaught UnexpectedValueException: Invalid version string "psd-files". (See below for the full stacktrace)
Describe what you would expect as the correct outcome
Update (patch release) to work.
Let us know what environment you are running this on
OS: Linux 4.19.0-12-cloud-amd64 #1 SMP Debian 4.19.152-1 (2020-10-18) x86_64
Shell: /bin/bash
PHP binary: /usr/bin/php7.4
PHP version: 7.4.12
php.ini used: /etc/php/7.4/cli/php.ini
WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir: phar://wp-cli.phar/vendor
WP_CLI phar path: /etc/cron.d
WP-CLI packages dir:
WP-CLI global config: ~/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version: 2.4.0
(Using Bedrock)
Provide a possible solution
- I suggest to catch errors from
Composer\Semver\Semver::satisfies(). - I suggest to output the plugin which actually failed. That would spare command-line run/bissecting time (The string
psd-filesis nowhere on the filesystem. Not even~/.composer/cache).
Provide additional context/Screenshots
https://plugins.svn.wordpress.org/wp-maintenance-mode/tags/
Shows that a psd-files tags was added.
When wp-maintenance-mode is at the latest version already, it seems the psd-files tag is omitted.
But if not, then it triggers an error at /composer/semver/src/VersionParser.php:172 which is not caught.
PHP Fatal error: Uncaught UnexpectedValueException: Invalid version string "psd-files" in phar:///usr/local/bin/wp/vendor/composer/semver/src/VersionParser.php:172
Stack trace:
#0 phar:///usr/local/bin/wp/vendor/composer/semver/src/Semver.php(39): Composer\Semver\VersionParser->normalize()
#1 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/utils.php(785): Composer\Semver\Semver::satisfies()
#2 phar:///usr/local/bin/wp/vendor/wp-cli/extension-command/src/WP_CLI/CommandWithUpgrade.php(583): WP_CLI\Utils\get_named_sem_ver()
#3 phar:///usr/local/bin/wp/vendor/wp-cli/extension-command/src/WP_CLI/CommandWithUpgrade.php(342): WP_CLI\CommandWithUpgrade->get_minor_or_patch_updates()
#4 phar:///usr/local/bin/wp/vendor/wp-cli/extension-command/src/Plugin_Command.php(640): WP_CLI\CommandWithUpgrade->update_many()
#5 [internal function]: Plugin_Command->update()
#6 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php(98): call_user_func()
#7 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\ in phar:///usr/local/bin/wp/vendor/composer/semver/src/VersionParser.php on line 172
Fatal error: Uncaught UnexpectedValueException: Invalid version string "psd-files" in phar:///usr/local/bin/wp/vendor/composer/semver/src/VersionParser.php:172
Stack trace:
#0 phar:///usr/local/bin/wp/vendor/composer/semver/src/Semver.php(39): Composer\Semver\VersionParser->normalize()
#1 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/utils.php(785): Composer\Semver\Semver::satisfies()
#2 phar:///usr/local/bin/wp/vendor/wp-cli/extension-command/src/WP_CLI/CommandWithUpgrade.php(583): WP_CLI\Utils\get_named_sem_ver()
#3 phar:///usr/local/bin/wp/vendor/wp-cli/extension-command/src/WP_CLI/CommandWithUpgrade.php(342): WP_CLI\CommandWithUpgrade->get_minor_or_patch_updates()
#4 phar:///usr/local/bin/wp/vendor/wp-cli/extension-command/src/Plugin_Command.php(640): WP_CLI\CommandWithUpgrade->update_many()
#5 [internal function]: Plugin_Command->update()
#6 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php(98): call_user_func()
#7 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\ in phar:///usr/local/bin/wp/vendor/composer/semver/src/VersionParser.php on line 172
Error: There has been a critical error on your website.Learn more about debugging in WordPress. There has been a critical error on your website
It's happening again (I guess wp-maintenance-mode produced a new major release) and blocks wp plugin update
I can't replicate this currently. It looks like the misformed tag was removed again, so I assume this also does create problems in other areas of the WP.org ecosystem.
Nevertheless, I agree that the code needs to be more robust to fail gracefully if unexpected data is fed to it.
This same bug occurs with eg. Elementor plugin, see https://github.com/elementor/elementor/issues/13090 .
I have a proposal for a fix in https://github.com/Seravo/wp-cli/commit/a148282d16d14c42e35c722cf0fe9f156b94389c , didn't yet open a PR however as I don't currently have time to make this commit compatible with PR guidelines described at https://make.wordpress.org/cli/handbook/contributions/pull-requests/ .