Repository navigation
Return a failure exit code from plugin:install-or-update when a plugin fails - #25873
AltamashShaikh wants to merge 2 commits into
Conversation
…n fails The command printed an error for each plugin it could not install or update but always exited with 0, so scripts could not detect the failure. It still tries every requested plugin, then exits with 1 if any of them failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sgiehl
left a comment
There was a problem hiding this comment.
Thanks, the fix itself looks good. Two things on the test, see inline.
| StaticContainer::getContainer()->set(PluginInstaller::class, $this->pluginInstaller); | ||
| } | ||
|
|
||
| public function testFailingInstallReturnsNonZeroExitCodeAndStillTriesTheOtherPlugins(): void |
There was a problem hiding this comment.
This only covers the case where every plugin fails. The more realistic case is mixed: one plugin installs fine, a later one fails, and the command should still exit with 1. That would also catch a regression where the flag gets reset on success.
Could you add a test for that? Keep in mind that the success path goes through Manager::loadPlugin() and Manager::installLoadedPlugins(), and the latter loops over all loaded plugins. The test shouldn't actually install or activate anything, so there's nothing that needs to be undone afterwards. One way is to also replace the plugin manager in DI.
There was a problem hiding this comment.
Auto-fix agent: Added testSuccessfulInstallFollowedByFailingInstallReturnsFailureExitCode: FirstPlugin installs successfully, SecondPlugin fails, and the command must exit with 1. The plugin manager is replaced in DI with a subclass that intercepts loadPlugin('FirstPlugin') and installLoadedPlugins(), so nothing is actually loaded, installed or activated; the console still loads its commands normally. The test also asserts both calls happened once, and tearDown restores the original manager and installer in DI.
| 'plugin' => ['FirstPlugin', 'SecondPlugin'], | ||
| ]); | ||
|
|
||
| self::assertNotSame(0, $result, $this->getCommandDisplayOutputErrorMessage()); |
There was a problem hiding this comment.
assertNotSame(0, ...) also passes if the command fails for some other reason, e.g. an uncaught exception. Please assert the exact exit code:
self::assertSame(1, $result, $this->getCommandDisplayOutputErrorMessage());There was a problem hiding this comment.
Auto-fix agent: Changed it to self::assertSame(1, $result, ...) and used the same exact assertion in the new mixed-case test.
…a later one fails Assert the exact failure exit code, and cover the mixed case where the first plugin installs successfully and a later one fails, without loading or installing anything. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Auto-fix agent: pushed 28e3781 for the review feedback. Test-only changes in this round: the existing test now asserts the exact exit code 1. Changed:
|
Description
When
./console plugin:install-or-updatecannot install or update a plugin (for example when the Marketplace returns an error or the rate limit is reached), it printsUnable to install or update plugin X. ...but still exits with code0. Scripts and automation therefore cannot detect the failure.Root cause:
InstallPlugin::doExecute()catchesPluginInstallerExceptionfor each plugin, prints the error and continues, but always returnsself::SUCCESSat the end.Fix: track whether any plugin failed. The command still tries every requested plugin (unchanged), then returns
self::FAILURE(exit code 1) if at least one failed andself::SUCCESSotherwise. Successful runs behave exactly as before.Tests: added
plugins/CorePluginsAdmin/tests/Integration/Commands/InstallPluginTest.php. It replacesPluginInstallerin DI with a mock that throwsPluginInstallerException, runsplugin:install-or-update FirstPlugin SecondPluginand asserts a non-zero exit code, that both plugins were attempted and that both errors were printed. The test failed before the fix (exit code 0) and passes with it. PHPCS and PHPStan pass on the changed files. No browser QA: this is a CLI-only change.QA
No browser check: the bug has no visible part.
Steps:
Checklist
Review
🤖 Generated with Claude Code
Fixes #24957