Problem/Motivation

Could not instantiate Drupal\photoswipe\Drush\Commands\PhotoswipeCommands: Too few arguments to function Drupal\photoswipe\Drush\Commands\PhotoswipeCommands::__construct(), 0 passed in /vendor/drush/drush/src/Runtime/ServiceManager.php on line 434 and exactly 2 expected

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork photoswipe-3639469

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

anybody created an issue. See original summary.

anybody’s picture

Assigned: Unassigned » anybody

It's a regression from #3605632: Replace "photoswipe.drush.inc" with a native Drupal 11 "DrushCommands" class

I'll prepare a fix and add a test!

anybody’s picture

Status: Active » Needs review

My fault, I didn't review carefully enough. -.-

anybody’s picture

Confirmed. Drush 12+ auto-discovers command classes in src/Drush/Commands/ and only injects dependencies through a static create() factory. Without one, it falls back to new $class() (see Drush\Runtime\ServiceManager::instantiateServices()), which fails because PhotoswipeCommands::__construct() requires two arguments. The error is only logged at debug level. The command kept working because the deprecated drush.services.yml registered it a second time.

Pushed to the issue fork (3639469-could-not-instantiate):

  • PhotoswipeCommands now uses Drush\Commands\AutowireTrait. Both constructor types (GuzzleHttp\ClientInterface, Drupal\Core\File\FileSystemInterface) have service aliases in core, so no explicit wiring is needed.
  • Removed the deprecated drush.services.yml.
  • Added the kernel test PhotoswipeCommandsTest::testCommandCanBeInstantiatedByDrush(), which builds the command via create() the way Drush does. It fails without the fix and passes with it.

Note: AutowireTrait requires Drush 12.5+. If older Drush 12 releases must be supported, a hand-written create() would work instead.

Still needed: an MR from the issue branch, and a manual check with drush photoswipe:install-plugin (and drush list -vvv to confirm the debug message is gone).

AI disclaimer: This analysis, fix and test were created with the help of AI (Claude Code) and reviewed by me.

  • anybody committed d38bb2f8 on 5.x
    fix: #3639469 Could not instantiate PhotoswipeCommands
    
grevil’s picture

Status: Needs review » Reviewed & tested by the community
grevil’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.