Skip to content

broken commands kill occ #33895

Open

Description

@butonic

If an app ships with an incompatible command the occ command will be broken and unusable, eg:

An unhandled exception has been thrown:
ArgumentCountError: Too few arguments to function OCA\User_LDAP\Command\Search::__construct(), 0 passed in /var/www/owncloud/lib/private/Console/Application.php on line 170 and exactly 3 expected in /var/www/owncloud/apps/user_ldap/lib/Command/Search.php:50
Stack trace:
#0 /var/www/owncloud/lib/private/Console/Application.php(170): OCA\User_LDAP\Command\Search->__construct()
#1 /var/www/owncloud/lib/private/Console/Application.php(108): OC\Console\Application->loadCommandsFromInfoXml(Array)
#2 /var/www/owncloud/console.php(105): OC\Console\Application->loadCommands(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 /var/www/owncloud/occ(11): require_once('/var/www/ownclo...')
#4 {main}

private function loadCommandsFromInfoXml($commands) {
foreach ($commands as $command) {
try {
$c = \OC::$server->query($command);
} catch (QueryException $e) {
if (\class_exists($command)) {
$c = new $command();
} else {
throw new \Exception("Console command '$command' is unknown and could not be loaded");
}
}
$this->application->add($c);
}
}

  • add ILogger to DI,
  • log an error
  • skip to the next command
  • add tests ... currently not covered AFAICT

Activity

  1. ownclouders commented on Dec 14, 2018

    @ownclouders
    Contributor

    GitMate.io thinks possibly related issues are #13402 (... broken), #24494 (occ command to clear all locks), #13976 (Kill OC_Request), #25964 (occ-.htaccess generation breaks .htaccess), and #30177 (Kill occ command maintenance:createjs).

  2. added this to the backlog milestone on Jan 11, 2019
  3. Kanishksgithub commented on Nov 16, 2023

    @Kanishksgithub

    i want to work on this could you briefly define exactly what i have to do in this issue

  4. DeepDiver1975 commented on Nov 16, 2023

    @DeepDiver1975
    Contributor

    i want to work on this could you briefly define exactly what i have to do in this issue

    instead of throwing the exception write a log statement - this way the loop will finish and all other commands are available ....

  5. Kanishksgithub commented on Nov 16, 2023

    @Kanishksgithub

    could you assign me i want to work on this issue

  6. Kanishksgithub commented on Nov 16, 2023

    @Kanishksgithub

    i want to fix this bug

  7. DeepDiver1975 commented on Nov 16, 2023

    @DeepDiver1975
    Contributor

    could you assign me i want to work on this issue

    Just go for it an submit your pull request. THX a lot! 🙏

  8. DeepDiver1975 commented on Jun 19, 2026

    @DeepDiver1975
    Contributor

    Classification: confirmed-bug (still reproducible on master)

    🤖 Automated issue analysis by Claude Code review agent.

    This is still present and unfixed on current master. The offending code in lib/private/Console/Application.php is essentially unchanged since 2016:

    private function loadCommandsFromInfoXml($commands) {
        foreach ($commands as $command) {
            try {
                $c = \OC::$server->query($command);
            } catch (QueryException $e) {
                if (\class_exists($command)) {
                    $c = new $command();          // <-- can throw \Error
                } else {
                    throw new \Exception("Console command '$command' is unknown and could not be loaded");
                }
            }
            $this->application->addCommand($c);
        }
    }

    Root cause. When a command class declares constructor dependencies that the DI container cannot resolve, \OC::$server->query($command) throws QueryException, which is caught. The fallback then calls new $command() with no arguments. For a command whose constructor has required parameters (e.g. OCA\User_LDAP\Command\Search::__construct() expecting 3 args, as in the report) this raises an ArgumentCountError (a \Error/\Throwable, not a QueryException or \Exception). That error is not caught here, propagates up through loadCommands(), and aborts the entire occ bootstrap — so a single broken app command makes all commands unusable.

    Two distinct problems remain in this method:

    1. new $command() is unguarded against \Error/\Throwable thrown by the constructor (the actual crash in the report).
    2. The else branch throw new \Exception(...) also aborts the whole loop rather than skipping the one bad command.

    The maintainer's earlier guidance still applies: instead of throwing/letting it bubble, log an error and continue to the next command so the rest of occ stays available. The original checklist is still open:

    • add ILogger to DI (the constructor currently takes only IConfig, EventDispatcherInterface, IRequest — no logger is injected)
    • log an error
    • skip to the next command
    • add tests (this path is still uncovered)

    Suggested shape of the fix: wrap the per-command load (query + new $command() fallback + addCommand) in a try { ... } catch (\Throwable $e) { $this->logger->logException($e, ['app' => 'core']); continue; } so one incompatible command is logged and skipped instead of killing occ.

    This is a junior-friendly, well-scoped fix. No PR is being opened automatically.

  9. DeepDiver1975 commented on Jun 19, 2026

    @DeepDiver1975
    Contributor

    🤖 Follow-up: opened a fix — #41642. It wraps each command load in try/catch (\Throwable) so a broken command is logged via ILogger and skipped instead of killing occ; the existing query/new $command()/unknown-class path and the success behavior are unchanged. Includes a regression test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions