fix(console): write app command loading errors to stderr - #62718
Open
printminion-co wants to merge 1 commit into
Open
fix(console): write app command loading errors to stderr#62718printminion-co wants to merge 1 commit into
printminion-co wants to merge 1 commit into
Conversation
printminion-co
requested review from
Altahrim,
come-nc,
provokateurin and
salmart-dev
and removed request for
a team
July 31, 2026 08:10
printminion-co
force-pushed
the
mk/fix/occ-console-command-load-error-to-stderr
branch
from
July 31, 2026 08:14
1b5de99 to
281a0cc
Compare
When an app fails to load its commands from info.xml, the error was
written to stdout, while every other diagnostic in loadCommands() uses
$output->getErrorOutput(). The command itself then runs normally and
exits 0, so the message silently corrupts machine-readable output:
$ ./occ app:list --output=json
Connection refused
{"enabled":{...},"disabled":{...}}
$ echo $?
0
Anything piping `occ <cmd> --output=json` into a JSON parser breaks, with
no non-zero exit code to detect it by.
Observed with notify_push on a setup that has the phpredis extension
loaded but no Redis configured: RedisFactory::isAvailable() only checks
whether the extension is loaded, so constructing the app's console
commands ends up calling pconnect() and throws RedisException.
--no-warnings is not a workaround for this, as it sets VERBOSITY_QUIET
and suppresses the payload too.
Route the message to the error output instead. It is still reported via
logger->error() exactly as before.
Assisted-by: ClaudeCode:claude-opus-5
Signed-off-by: Misha M.-Kupriyanov <kupriyanov@strato.de>
printminion-co
force-pushed
the
mk/fix/occ-console-command-load-error-to-stderr
branch
from
July 31, 2026 08:15
281a0cc to
9345ce5
Compare
10 tasks
artonge
approved these changes
Jul 31, 2026
artonge
left a comment
Collaborator
There was a problem hiding this comment.
Makes sense, cc @icewind1991 and @bigcat88 as original author of those lines.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When an app fails to load its console commands from
info.xml,OC\Console\Application::loadCommands()reports the failure with$output->writeln()— i.e. stdout — while every other diagnostic in the same method already uses$output->getErrorOutput()(insufficient memory limit, "Nextcloud is not installed", "requires upgrade", maintenance-mode notices).The command then runs normally and exits
0, so the message silently corrupts machine-readable output:Anything piping
occ <cmd> --output=jsoninto a JSON parser breaks, and there is no non-zero exit code to detect it by.--no-warningsis not a workaround, since it setsVERBOSITY_QUIETand suppresses the payload too.$outputis typedConsoleOutputInterface, sogetErrorOutput()is guaranteed by the signature. Two call sites are affected: theapp_apimaintenance-mode block and the regular installed-apps loop. Thelogger->error()calls are unchanged, so the failure is still logged with its stack trace.How this was hit
An app with the phpredis extension loaded but no Redis configured.
RedisFactory::isAvailable()only checksextension_loaded('redis'), not whether aredisconfig block exists, so the app's queue factory took the Redis branch, fell back to127.0.0.1:6379and threwRedisException: Connection refusedwhile its console commands were being constructed. Becauseenable_lazy_objectsdefaults totrue, the constructor runs inside$this->application->add($c)→Command::setApplication(), so the throw surfaces outsideloadCommandsFromInfoXml()'s innercatch (ContainerExceptionInterface)and lands in the outercatch (\Throwable).The app-side behaviour is arguably its own issue; the console bootstrap should not corrupt stdout regardless of which app fails to load.
Verification
Reproduced deterministically with a throwaway app whose
info.xmlnames a nonexistent command class:jqConsole command '...' is un…{"enabled":{...}The error remains in
nextcloud.log.On tests
No test is included. There is currently no test for
lib/private/Console/*, andgrep -rn getErrorOutput tests/returns nothing, so there is no existing harness or stdout-vs-stderr assertion precedent to extend.loadCommands()also does an unstubbablerequire_once core/register_command.php(~138Server::get()calls, re-fetching the realIConfigrather than an injected mock), which makes a genuine unit test a DB-group test whose result is order-dependent becauserequire_onceruns once per process.This change adds no logic — it only redirects an existing message from one stream to the other. Happy to add a
build/integrationscenario (CommandLine.phpalready captures stdout and stderr separately) or to extract thatrequire_oncebehind an injected collaborator to make the class unit-testable, if a maintainer would prefer either.Checklist
Signed-off-byis present (added by the contributor)AI disclosure
This change and this description were drafted with AI assistance (Claude Code, claude-opus-5), then reviewed by the submitting contributor. Disclosed per the Nextcloud AI Contribution Policy.