Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composer2: InvalidArgumentException when plugin install fails #8764

Closed
villfa opened this issue Apr 10, 2020 · 4 comments
Closed

Composer2: InvalidArgumentException when plugin install fails #8764

villfa opened this issue Apr 10, 2020 · 4 comments

Comments

@villfa
Copy link
Contributor

villfa commented Apr 10, 2020

Related to #8726 .

I'm testing my plugin with Composer 2:

$ pwd
/home/villfa/test_plugin

$ ./composer --version
Composer version 2.0-dev (2.0-dev+40a35abb9423e16f8bafcb1ed1b7e027881b0422) 2020-04-10 10:24:43

$ cat composer.json 
{
    "require": {
        "villfa/composer-substitution-plugin": "dev-master"
    },
    "repositories": [
        {"type":"path", "url": "../composer-substitution-plugin"}
    ],
    "minimum-stability": "dev",
    "scripts": {
        "foo": "echo {FOO}"
    },
    "extra": {
        "substitution": {
            "enable": true,
            "mapping": {
                "{FOO}": {
                    "type": "literal",
                    "value": "Hello world"
                }
            }
        }
    }
}

$ rm -rf composer.lock vendor/

$ ./composer -vvv install
Reading ./composer.json
Loading config file ./composer.json
Checked CA file /etc/ssl/certs/ca-certificates.crt: valid
Executing command (/home/villfa/test_plugin): git branch --no-color --no-abbrev -v
Executing command (/home/villfa/test_plugin): git describe --exact-match --tags
Executing command (/home/villfa/test_plugin): git log --pretty="%H" -n1 HEAD
Executing command (/home/villfa/test_plugin): hg branch
Executing command (/home/villfa/test_plugin): fossil branch list
Executing command (/home/villfa/test_plugin): fossil tag list
Executing command (/home/villfa/test_plugin): svn info --xml
Reading /home/villfa/.config/composer/composer.json
Loading config file /home/villfa/.config/composer/composer.json
Reading /home/villfa/.config/composer/vendor/composer/installed.json
Running 2.0-dev+40a35abb9423e16f8bafcb1ed1b7e027881b0422 (2020-04-10 10:24:43) with PHP 7.2.24-0ubuntu0.19.04.2 on Linux / 5.0.0-38-generic
No lock file found. Updating dependencies instead of installing from lock file. Use composer update over composer install if you do not have a lock file.
Loading composer repositories with package information
Updating dependencies
Executing command (/home/villfa/composer-substitution-plugin/): git log -n1 --pretty=%H
Executing command (/home/villfa/composer-substitution-plugin/): git branch --no-color --no-abbrev -v
Downloading https://repo.packagist.org/packages.json
[200] https://repo.packagist.org/packages.json
Writing /home/villfa/.cache/composer/repo/https---repo.packagist.org/packages.json into cache
Generating rules
Resolving dependencies through SAT
Looking at all rules.

Dependency resolution completed in 0.000 seconds
Analyzed 54 packages to resolve dependencies
Analyzed 55 rules to resolve dependencies
Lock file operations: 1 install, 0 updates, 0 removals
Installs: villfa/composer-substitution-plugin:dev-master
  - Locking villfa/composer-substitution-plugin (dev-master)
Writing lock file
Installing dependencies from lock file (including require-dev)
Reading ./composer.lock
Package operations: 1 install, 0 updates, 0 removals
Installs: villfa/composer-substitution-plugin:dev-master
  - Installing villfa/composer-substitution-plugin (dev-master): Symlinking from ../composer-substitution-plugin
Loading plugin SubstitutionPlugin\SubstitutionPlugin
[SubstitutionPlugin] Plugin enabled. Priority set to 0.
    Install of villfa/composer-substitution-plugin failed
  - Marking villfa/composer-substitution-plugin (9999999-dev) as installed, alias of villfa/composer-substitution-plugin (dev-master)

                                                                                              
  [InvalidArgumentException]                                                                  
  The "/home/villfa/test_plugin/vendor/composer/" directory does not exist.  
                                                                                              

Exception trace:
 () at phar:///home/villfa/test_plugin/composer/vendor/symfony/finder/Finder.php:657
 Symfony\Component\Finder\Finder->in() at phar:///home/villfa/test_plugin/composer/src/Composer/Util/Filesystem.php:59
 Composer\Util\Filesystem->isDirEmpty() at phar:///home/villfa/test_plugin/composer/src/Composer/Downloader/FileDownloader.php:242
 Composer\Downloader\FileDownloader->cleanup() at phar:///home/villfa/test_plugin/composer/src/Composer/Downloader/DownloadManager.php:361
 Composer\Downloader\DownloadManager->cleanup() at phar:///home/villfa/test_plugin/composer/src/Composer/Installer/LibraryInstaller.php:118
 Composer\Installer\LibraryInstaller->cleanup() at phar:///home/villfa/test_plugin/composer/src/Composer/Installer/InstallationManager.php:240
 Composer\Installer\InstallationManager->Composer\Installer\{closure}() at phar:///home/villfa/test_plugin/composer/src/Composer/Installer/InstallationManager.php:270
 Composer\Installer\InstallationManager->Composer\Installer\{closure}() at n/a:n/a
 call_user_func() at phar:///home/villfa/test_plugin/composer/vendor/react/promise/src/React/Promise/Promise.php:49
 React\Promise\Promise->call() at phar:///home/villfa/test_plugin/composer/vendor/react/promise/src/React/Promise/Promise.php:21
 React\Promise\Promise->__construct() at phar:///home/villfa/test_plugin/composer/src/Composer/Installer/InstallationManager.php:278
 Composer\Installer\InstallationManager->execute() at phar:///home/villfa/test_plugin/composer/src/Composer/Installer.php:677
 Composer\Installer->doInstall() at phar:///home/villfa/test_plugin/composer/src/Composer/Installer.php:523
 Composer\Installer->doUpdate() at phar:///home/villfa/test_plugin/composer/src/Composer/Installer.php:242
 Composer\Installer->run() at phar:///home/villfa/test_plugin/composer/src/Composer/Command/InstallCommand.php:119
 Composer\Command\InstallCommand->execute() at phar:///home/villfa/test_plugin/composer/vendor/symfony/console/Command/Command.php:245
 Symfony\Component\Console\Command\Command->run() at phar:///home/villfa/test_plugin/composer/vendor/symfony/console/Application.php:835
 Symfony\Component\Console\Application->doRunCommand() at phar:///home/villfa/test_plugin/composer/vendor/symfony/console/Application.php:185
 Symfony\Component\Console\Application->doRun() at phar:///home/villfa/test_plugin/composer/src/Composer/Console/Application.php:287
 Composer\Console\Application->doRun() at phar:///home/villfa/test_plugin/composer/vendor/symfony/console/Application.php:117
 Symfony\Component\Console\Application->run() at phar:///home/villfa/test_plugin/composer/src/Composer/Console/Application.php:113
 Composer\Console\Application->run() at phar:///home/villfa/test_plugin/composer/bin/composer:61
 require() at /home/villfa/test_plugin/composer:25

install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--] [<packages>]...

$ ./composer diagnose
Checking composer.json: WARNING
No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking pubkeys: 
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0  87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B  0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: OK
Composer version: 2.0-dev+40a35abb9423e16f8bafcb1ed1b7e027881b0422
PHP version: 7.2.24
PHP binary path: /usr/bin/php7.2
OpenSSL version: OpenSSL 1.1.1b  26 Feb 2019

Now if I remove the plugin and add it again then it works:

$ ./composer remove villfa/composer-substitution-plugin
Loading composer repositories with package information
Updating dependencies
Lock file operations: 0 installs, 0 updates, 1 removal
  - Removing villfa/composer-substitution-plugin (dev-master)
Writing lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Generating autoload files

$ ./composer require villfa/composer-substitution-plugin:dev-master
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
  - Locking villfa/composer-substitution-plugin (dev-master)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing villfa/composer-substitution-plugin (dev-master): Source already present
Generating autoload files

$ ./composer foo
> echo Hello world
Hello world

Also I have no error if I remove the repositories section before executing the install command.

@villfa
Copy link
Contributor Author

villfa commented Apr 10, 2020

I had a bug in my own plugin (a file was not included so a function was not defined), I think that's why I got this line:

Install of villfa/composer-substitution-plugin failed

Now that it's fixed the installation completes with no problem.

I let this issue open because I think the error message was misleading and could be improved.

Feel free to close it if you think otherwise.

@villfa villfa changed the title Composer2: install fails with only a local repository Composer2: wrong error message when plugin install fails Apr 10, 2020
@villfa villfa changed the title Composer2: wrong error message when plugin install fails Composer2: InvalidArgumentException when plugin install fails Apr 10, 2020
@stof
Copy link
Contributor

stof commented Apr 10, 2020

Well, the thing is, the bug in the cleanup means that the original error git hidden by it (because the cleanup logic running before rethrowing the original error is throwing itself).

@stof
Copy link
Contributor

stof commented Apr 10, 2020

See my comment in #8766

@Seldaek
Copy link
Member

Seldaek commented Apr 13, 2020

Should work with latest snapshot, well the plugin install might still fail but at least you should see the real error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants