Skip to content

Return a failure exit code from plugin:install-or-update when a plugin fails - #25873

Open
AltamashShaikh wants to merge 2 commits into
6.x-devfrom
DEV-20590
Open

AltamashShaikh wants to merge 2 commits into
6.x-devfrom
DEV-20590

Conversation

@AltamashShaikh

Copy link
Copy Markdown
Contributor

Description

When ./console plugin:install-or-update cannot install or update a plugin (for example when the Marketplace returns an error or the rate limit is reached), it prints Unable to install or update plugin X. ... but still exits with code 0. Scripts and automation therefore cannot detect the failure.

Root cause: InstallPlugin::doExecute() catches PluginInstallerException for each plugin, prints the error and continues, but always returns self::SUCCESS at 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 and self::SUCCESS otherwise. Successful runs behave exactly as before.

Tests: added plugins/CorePluginsAdmin/tests/Integration/Commands/InstallPluginTest.php. It replaces PluginInstaller in DI with a mock that throws PluginInstallerException, runs plugin:install-or-update FirstPlugin SecondPlugin and 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:

  1. CLI-only change, nothing to see in a browser. 2. Tried running ./console plugin:install-or-update NoSuchPluginXyz on the test install, but it has no regular database (only the test DB), so the command cannot boot there. 3. Behaviour verified through the integration test, which runs the real command via Matomo's console application.

Checklist

  • [✖] I have understood, reviewed, and tested all AI outputs before use
  • [✔] All AI instructions respect security, IP, and privacy rules

Review

🤖 Generated with Claude Code

Fixes #24957

…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>
@AltamashShaikh AltamashShaikh added this to the 6.1.0 milestone Nov 30, 2026
@AltamashShaikh
AltamashShaikh requested a review from a team November 30, 2026 08:09

@sgiehl sgiehl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, the fix itself looks good. Two things on the test, see inline.

StaticContainer::getContainer()->set(PluginInstaller::class, $this->pluginInstaller);
}

public function testFailingInstallReturnsNonZeroExitCodeAndStillTriesTheOtherPlugins(): void

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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>
@AltamashShaikh

Copy link
Copy Markdown
Contributor Author

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.
Added a test for the mixed case where one plugin installs and a later one fails, which still has to exit with 1. The test replaces the plugin manager in DI so nothing is actually installed.

Changed:

  • plugins/CorePluginsAdmin/tests/Integration/Commands/InstallPluginTest.php

@AltamashShaikh
AltamashShaikh requested a review from sgiehl December 1, 2026 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

[Bug] When plugin:install-or-update fails, it still returns an exit code of 0

2 participants