Gracefully handle missing version constraints#80
Gracefully handle missing version constraints#80jordantrizz wants to merge 1 commit intoaaemnnosttv:masterfrom
Conversation
3efb33a to
f656e84
Compare
* Gracefully handle missing version constraints. * Set plugin version to semver requirements 0.0.0
aaemnnosttv
left a comment
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
The version constraint has been saved in the endpoint definition and server plugin header since version 1.0
|
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. |
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.
Resolution
You can delete the stored option by running
Summary
Error
Testing