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

The 'get another view on the problem' message shouldn't suggest impossible commands #11690

Closed
joachim-n opened this issue Oct 17, 2023 · 10 comments · Fixed by #11691 or #11692
Closed

The 'get another view on the problem' message shouldn't suggest impossible commands #11690

joachim-n opened this issue Oct 17, 2023 · 10 comments · Fixed by #11691 or #11692
Labels
Milestone

Comments

@joachim-n
Copy link

My composer.json:

{
    "name": "drupal/recommended-project",
    "description": "Project template for Drupal 9 projects with a relocated document root",
    "type": "project",
    "license": "GPL-2.0-or-later",
    "homepage": "https://www.drupal.org/project/drupal",
    "support": {
        "docs": "https://www.drupal.org/docs/user_guide/en/index.html",
        "chat": "https://www.drupal.org/node/314178"
    },
    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        }
    ],
    "require": {
        "composer/installers": "^1.9",
        "dealerdirect/phpcodesniffer-composer-installer": "*",
        "drupal/admin_toolbar": "^3.2",
        "drupal/coder": "^8.3",
        "drupal/computed_field_plugin": "^1.3",
        "drupal/core-composer-scaffold": "^9.4",
        "drupal/core-dev": "^9.4",
        "drupal/core-recommended": "^9.5",
        "drupal/ctools": "^4.0",
        "drupal/devel": "^5.0",
        "drupal/devel_entity_updates": "^4.1",
        "drupal/filelog": "^2.1",
        "drupal/flag": "^4.0@beta",
        "drupal/module_builder": "^3.24",
        "drupal/token": "^1.11",
        "drupal/ultimate_cron": "^2.0@alpha",
        "drush/drush": "^11.2",
        "edemeijer/serialize-debugger": "^0.1.4",
        "kint-php/kint": "^4.2",
        "phpspec/prophecy-phpunit": "^2"
    },
    "conflict": {
        "drupal/drupal": "*"
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "config": {
        "allow-plugins": {
            "composer/installers": true,
            "drupal/core-composer-scaffold": true,
            "dealerdirect/phpcodesniffer-composer-installer": true
        },
        "sort-packages": true
    },
    "extra": {
        "drupal-scaffold": {
            "locations": {
                "web-root": "web/"
            }
        },
        "installer-paths": {
            "web/core": [
                "type:drupal-core"
            ],
            "web/libraries/{$name}": [
                "type:drupal-library"
            ],
            "web/modules/contrib/{$name}": [
                "type:drupal-module"
            ],
            "web/profiles/contrib/{$name}": [
                "type:drupal-profile"
            ],
            "web/themes/contrib/{$name}": [
                "type:drupal-theme"
            ],
            "drush/Commands/contrib/{$name}": [
                "type:drupal-drush"
            ],
            "web/modules/custom/{$name}": [
                "type:drupal-custom-module"
            ],
            "web/profiles/custom/{$name}": [
                "type:drupal-custom-profile"
            ],
            "web/themes/custom/{$name}": [
                "type:drupal-custom-theme"
            ]
        },
        "drupal-core-project-message": {
            "include-keys": [
                "homepage",
                "support"
            ],
            "post-create-project-cmd-message": [
                "<bg=blue;fg=white>                                                         </>",
                "<bg=blue;fg=white>  Congratulations, you’ve installed the Drupal codebase  </>",
                "<bg=blue;fg=white>  from the drupal/recommended-project template!          </>",
                "<bg=blue;fg=white>                                                         </>",
                "",
                "<bg=yellow;fg=black>Next steps</>:",
                "  * Install the site: https://www.drupal.org/docs/8/install",
                "  * Read the user guide: https://www.drupal.org/docs/user_guide/en/index.html",
                "  * Get support: https://www.drupal.org/support",
                "  * Get involved with the Drupal community:",
                "      https://www.drupal.org/getting-involved",
                "  * Remove the plugin that prints this message:",
                "      composer remove drupal/core-project-message"
            ]
        }
    }
}

Output of composer diagnose:

Checking composer.json: WARNING
require.dealerdirect/phpcodesniffer-composer-installer : unbound version constraints (*) should be avoided
Checking platform settings: OK
Checking git settings: OK git version 2.42.0
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.6.5
PHP version: 8.2.10
PHP binary path: /usr/local/Cellar/php/8.2.10/bin/php
OpenSSL version: OpenSSL 3.1.2 1 Aug 2023
cURL version: 8.3.0 libz 1.2.11 ssl (SecureTransport) OpenSSL/3.1.3
zip: extension present, unzip present, 7-Zip not available

When I run this command:

composer why-not drupal/core-recommended ^10.1 -vvv

I get the following output:


Running 2.6.5 (2023-10-06 10:11:52) with PHP 8.2.10 on Darwin / 22.6.0
Reading ./composer.json (/Users/joachim/Sites/drupal-contrib/composer.json)
Loading config file ./composer.json (/Users/joachim/Sites/drupal-contrib/composer.json)
Checked CA file /etc/pki/tls/certs/ca-bundle.crt does not exist or it is not a file.
Checked directory /etc/pki/tls/certs/ca-bundle.crt does not exist or it is not a directory.
Checked CA file /etc/ssl/certs/ca-certificates.crt does not exist or it is not a file.
Checked directory /etc/ssl/certs/ca-certificates.crt does not exist or it is not a directory.
Checked CA file /etc/ssl/ca-bundle.pem does not exist or it is not a file.
Checked directory /etc/ssl/ca-bundle.pem does not exist or it is not a directory.
Checked CA file /usr/local/share/certs/ca-root-nss.crt does not exist or it is not a file.
Checked directory /usr/local/share/certs/ca-root-nss.crt does not exist or it is not a directory.
Checked CA file /usr/ssl/certs/ca-bundle.crt does not exist or it is not a file.
Checked directory /usr/ssl/certs/ca-bundle.crt does not exist or it is not a directory.
Checked CA file /opt/local/share/curl/curl-ca-bundle.crt does not exist or it is not a file.
Checked directory /opt/local/share/curl/curl-ca-bundle.crt does not exist or it is not a directory.
Checked CA file /usr/local/share/curl/curl-ca-bundle.crt does not exist or it is not a file.
Checked directory /usr/local/share/curl/curl-ca-bundle.crt does not exist or it is not a directory.
Checked CA file /usr/share/ssl/certs/ca-bundle.crt does not exist or it is not a file.
Checked directory /usr/share/ssl/certs/ca-bundle.crt does not exist or it is not a directory.
Checked CA file /private/etc/ssl/cert.pem: valid
Executing command (/Users/joachim/Sites/drupal-contrib): 'git' 'branch' '-a' '--no-color' '--no-abbrev' '-v'
Executing command (/Users/joachim/Sites/drupal-contrib): git describe --exact-match --tags
Executing command (CWD): git --version
Executing command (/Users/joachim/Sites/drupal-contrib): git log --pretty="%H" -n1 HEAD --no-show-signature
Executing command (/Users/joachim/Sites/drupal-contrib): hg branch
Executing command (/Users/joachim/Sites/drupal-contrib): fossil branch list
Executing command (/Users/joachim/Sites/drupal-contrib): fossil tag list
Executing command (/Users/joachim/Sites/drupal-contrib): svn info --xml
Reading /Users/joachim/.composer/composer.json
Loading config file /Users/joachim/.composer/composer.json (/Users/joachim/.composer/composer.json)
Reading /Users/joachim/Sites/drupal-contrib/vendor/composer/installed.json
Reading /Users/joachim/.composer/vendor/composer/installed.json
Loading plugin Composer\Installers\Plugin (from composer/installers)
Loading plugin Dealerdirect\Composer\Plugin\Installers\PHPCodeSniffer\Plugin (from dealerdirect/phpcodesniffer-composer-installer)
Loading plugin Drupal\Composer\Plugin\Scaffold\Plugin (from drupal/core-composer-scaffold)
> command: Drupal\Composer\Plugin\Scaffold\Plugin->onCommand
Reading /Users/joachim/Library/Caches/composer/repo/https---packages.drupal.org-8/packages.json from cache
Downloading https://packages.drupal.org/8/packages.json if modified
[304] https://packages.drupal.org/8/packages.json
Downloading https://packages.drupal.org/files/packages/8/p2/drupal/core-recommended.json
Downloading https://packages.drupal.org/files/packages/8/p2/drupal/core-recommended~dev.json
[404] https://packages.drupal.org/files/packages/8/p2/drupal/core-recommended~dev.json
[404] https://packages.drupal.org/files/packages/8/p2/drupal/core-recommended.json
Reading /Users/joachim/Library/Caches/composer/repo/https---repo.packagist.org/packages.json from cache
Downloading https://repo.packagist.org/packages.json if modified
[304] https://repo.packagist.org/packages.json
Reading /Users/joachim/Library/Caches/composer/repo/https---repo.packagist.org/provider-drupal~core-recommended.json from cache
Downloading https://repo.packagist.org/p2/drupal/core-recommended.json if modified
Reading /Users/joachim/Library/Caches/composer/repo/https---repo.packagist.org/provider-drupal~core-recommended~dev.json from cache
Downloading https://repo.packagist.org/p2/drupal/core-recommended~dev.json if modified
[304] https://repo.packagist.org/p2/drupal/core-recommended.json
[304] https://repo.packagist.org/p2/drupal/core-recommended~dev.json
drupal/recommended-project -      requires         drupal/core-recommended (^9.5)
drupal/core-recommended    10.1.5 requires         drupal/core (10.1.5)
drupal/recommended-project -      does not require drupal/core (but 9.5.11 is installed)
drupal/core-recommended    10.1.5 requires         asm89/stack-cors (~v2.1.1)
drupal/recommended-project -      does not require asm89/stack-cors (but 1.3.0 is installed)
drupal/core-recommended    10.1.5 requires         doctrine/annotations (~1.14.3)
drupal/recommended-project -      does not require doctrine/annotations (but 1.13.3 is installed)
drupal/core-recommended    10.1.5 requires         doctrine/lexer (~2.1.0)
drupal/recommended-project -      does not require doctrine/lexer (but 1.2.3 is installed)
drupal/core-recommended    10.1.5 requires         egulias/email-validator (~4.0.1)
drupal/recommended-project -      does not require egulias/email-validator (but 3.2.6 is installed)
drupal/core-recommended    10.1.5 requires         guzzlehttp/guzzle (~7.7.0)
drupal/recommended-project -      does not require guzzlehttp/guzzle (but 6.5.8 is installed)
drupal/core-recommended    10.1.5 requires         guzzlehttp/psr7 (~2.5.0)
drupal/recommended-project -      does not require guzzlehttp/psr7 (but 1.9.1 is installed)
drupal/core-recommended    10.1.5 requires         masterminds/html5 (~2.8.0)
drupal/recommended-project -      does not require masterminds/html5 (but 2.7.6 is installed)
drupal/core-recommended    10.1.5 requires         psr/cache (~3.0.0)
drupal/recommended-project -      does not require psr/cache (but 1.0.1 is installed)
drupal/core-recommended    10.1.5 requires         psr/container (~2.0.2)
drupal/recommended-project -      does not require psr/container (but 1.1.2 is installed)
drupal/core-recommended    10.1.5 requires         psr/log (~3.0.0)
drupal/recommended-project -      does not require psr/log (but 1.1.4 is installed)
drupal/core-recommended    10.1.5 requires         symfony/console (~v6.3.0)
drupal/recommended-project -      does not require symfony/console (but v4.4.49 is installed)
drupal/core-recommended    10.1.5 requires         symfony/dependency-injection (~v6.3.0)
drupal/recommended-project -      does not require symfony/dependency-injection (but v4.4.49 is installed)
drupal/core-recommended    10.1.5 requires         symfony/deprecation-contracts (~v3.3.0)
drupal/recommended-project -      does not require symfony/deprecation-contracts (but v2.5.2 is installed)
drupal/core-recommended    10.1.5 requires         symfony/error-handler (~v6.3.0)
drupal/recommended-project -      does not require symfony/error-handler (but v4.4.44 is installed)
drupal/core-recommended    10.1.5 requires         symfony/event-dispatcher (~v6.3.0)
drupal/recommended-project -      does not require symfony/event-dispatcher (but v4.4.44 is installed)
drupal/core-recommended    10.1.5 requires         symfony/event-dispatcher-contracts (~v3.3.0)
drupal/recommended-project -      does not require symfony/event-dispatcher-contracts (but v1.1.13 is installed)
drupal/core-recommended    10.1.5 requires         symfony/http-foundation (~v6.3.0)
drupal/recommended-project -      does not require symfony/http-foundation (but v4.4.49 is installed)
drupal/core-recommended    10.1.5 requires         symfony/http-kernel (~v6.3.0)
drupal/recommended-project -      does not require symfony/http-kernel (but v4.4.50 is installed)
drupal/core-recommended    10.1.5 requires         symfony/mime (~v6.3.0)
drupal/recommended-project -      does not require symfony/mime (but v5.4.13 is installed)
drupal/core-recommended    10.1.5 requires         symfony/polyfill-intl-grapheme (~v1.27.0)
drupal/recommended-project -      does not require symfony/polyfill-intl-grapheme (but v1.28.0 is installed)
drupal/core-recommended    10.1.5 requires         symfony/process (~v6.3.0)
drupal/recommended-project -      does not require symfony/process (but v4.4.44 is installed)
drupal/core-recommended    10.1.5 requires         symfony/psr-http-message-bridge (~v2.2.0)
drupal/recommended-project -      does not require symfony/psr-http-message-bridge (but v2.1.4 is installed)
drupal/core-recommended    10.1.5 requires         symfony/routing (~v6.3.0)
drupal/recommended-project -      does not require symfony/routing (but v4.4.44 is installed)
drupal/core-recommended    10.1.5 requires         symfony/serializer (~v6.3.0)
drupal/recommended-project -      does not require symfony/serializer (but v4.4.47 is installed)
drupal/core-recommended    10.1.5 requires         symfony/service-contracts (~v3.3.0)
drupal/recommended-project -      does not require symfony/service-contracts (but v2.5.2 is installed)
drupal/core-recommended    10.1.5 requires         symfony/string (~v6.3.0)
drupal/recommended-project -      does not require symfony/string (but v6.0.19 is installed)
drupal/core-recommended    10.1.5 requires         symfony/translation-contracts (~v3.3.0)
drupal/recommended-project -      does not require symfony/translation-contracts (but v2.5.2 is installed)
drupal/core-recommended    10.1.5 requires         symfony/validator (~v6.3.0)
drupal/recommended-project -      does not require symfony/validator (but v4.4.48 is installed)
drupal/core-recommended    10.1.5 requires         symfony/var-dumper (~v6.3.0)
drupal/recommended-project -      does not require symfony/var-dumper (but v5.4.29 is installed)
drupal/core-recommended    10.1.5 requires         symfony/var-exporter (~v6.3.0)
drupal/recommended-project -      does not require symfony/var-exporter (but v6.0.19 is installed)
drupal/core-recommended    10.1.5 requires         symfony/yaml (~v6.3.0)
drupal/recommended-project -      does not require symfony/yaml (but v4.4.45 is installed)
drupal/core-recommended    10.1.5 requires         twig/twig (~v3.6.0)
drupal/recommended-project -      does not require twig/twig (but v2.15.5 is installed)
Not finding what you were looking for? Try calling `composer update "drupal/core-recommended:^10.1" --dry-run` to get another view on the problem.

But then this command, as instructed:

composer update "drupal/core-recommended:^10.1" --dry-run

produces this output:

Running 2.6.5 (2023-10-06 10:11:52) with PHP 8.2.10 on Darwin / 22.6.0
Reading ./composer.json (/Users/joachim/Sites/drupal-contrib/composer.json)
Loading config file ./composer.json (/Users/joachim/Sites/drupal-contrib/composer.json)
Checked CA file /etc/pki/tls/certs/ca-bundle.crt does not exist or it is not a file.
Checked directory /etc/pki/tls/certs/ca-bundle.crt does not exist or it is not a directory.
Checked CA file /etc/ssl/certs/ca-certificates.crt does not exist or it is not a file.
Checked directory /etc/ssl/certs/ca-certificates.crt does not exist or it is not a directory.
Checked CA file /etc/ssl/ca-bundle.pem does not exist or it is not a file.
Checked directory /etc/ssl/ca-bundle.pem does not exist or it is not a directory.
Checked CA file /usr/local/share/certs/ca-root-nss.crt does not exist or it is not a file.
Checked directory /usr/local/share/certs/ca-root-nss.crt does not exist or it is not a directory.
Checked CA file /usr/ssl/certs/ca-bundle.crt does not exist or it is not a file.
Checked directory /usr/ssl/certs/ca-bundle.crt does not exist or it is not a directory.
Checked CA file /opt/local/share/curl/curl-ca-bundle.crt does not exist or it is not a file.
Checked directory /opt/local/share/curl/curl-ca-bundle.crt does not exist or it is not a directory.
Checked CA file /usr/local/share/curl/curl-ca-bundle.crt does not exist or it is not a file.
Checked directory /usr/local/share/curl/curl-ca-bundle.crt does not exist or it is not a directory.
Checked CA file /usr/share/ssl/certs/ca-bundle.crt does not exist or it is not a file.
Checked directory /usr/share/ssl/certs/ca-bundle.crt does not exist or it is not a directory.
Checked CA file /private/etc/ssl/cert.pem: valid
Executing command (/Users/joachim/Sites/drupal-contrib): 'git' 'branch' '-a' '--no-color' '--no-abbrev' '-v'
Executing command (/Users/joachim/Sites/drupal-contrib): git describe --exact-match --tags
Executing command (CWD): git --version
Executing command (/Users/joachim/Sites/drupal-contrib): git log --pretty="%H" -n1 HEAD --no-show-signature
Executing command (/Users/joachim/Sites/drupal-contrib): hg branch
Executing command (/Users/joachim/Sites/drupal-contrib): fossil branch list
Executing command (/Users/joachim/Sites/drupal-contrib): fossil tag list
Executing command (/Users/joachim/Sites/drupal-contrib): svn info --xml
Reading /Users/joachim/.composer/composer.json
Loading config file /Users/joachim/.composer/composer.json (/Users/joachim/.composer/composer.json)
Reading /Users/joachim/Sites/drupal-contrib/vendor/composer/installed.json
Reading /Users/joachim/.composer/vendor/composer/installed.json
Loading plugin Composer\Installers\Plugin (from composer/installers)
Loading plugin Dealerdirect\Composer\Plugin\Installers\PHPCodeSniffer\Plugin (from dealerdirect/phpcodesniffer-composer-installer)
Loading plugin Drupal\Composer\Plugin\Scaffold\Plugin (from drupal/core-composer-scaffold)

In UpdateCommand.php line 163:

  [InvalidArgumentException]
  The temporary constraint "^10.1" for "drupal/core-recommended" must be a subset of the constraint in your composer.json (^9.5)


Exception trace:
  at phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/Command/UpdateCommand.php:163
 Composer\Command\UpdateCommand->execute() at phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/vendor/symfony/console/Command/Command.php:298
 Symfony\Component\Console\Command\Command->run() at phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/vendor/symfony/console/Application.php:1040
 Symfony\Component\Console\Application->doRunCommand() at phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/vendor/symfony/console/Application.php:301
 Symfony\Component\Console\Application->doRun() at phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/Console/Application.php:382
 Composer\Console\Application->doRun() at phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/vendor/symfony/console/Application.php:171
 Symfony\Component\Console\Application->run() at phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/Console/Application.php:145
 Composer\Console\Application->run() at phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/bin/composer:93
 require() at /usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar:29

update [--with WITH] [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--dry-run] [--dev] [--no-dev] [--lock] [--no-install] [--no-audit] [--audit-format AUDIT-FORMAT] [--no-autoloader] [--no-suggest] [--no-progress] [-w|--with-dependencies] [-W|--with-all-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [-i|--interactive] [--root-reqs] [--] [<packages>...]

And I expected this to happen:

Composer should not tell me to run a command that it then tells me it can't run.

@stof
Copy link
Contributor

stof commented Oct 17, 2023

Well, technically, this gives you another view of the problem: this error indicates that the root package itself has a requirement forbidding to use this version (which was already there in the other output as drupal/recommended-project - requires drupal/core-recommended (^9.5) but might have been missed)

@stof
Copy link
Contributor

stof commented Oct 17, 2023

and the case where your own composer.json forbids it is the only case where the other command will fail early instead of running the solver.

@joachim-n
Copy link
Author

It crashes with an [InvalidArgumentException], and without -vvv that's all you see.

@joachim-n
Copy link
Author

the root package itself has a requirement forbidding to use this version (which was already there in the other output as drupal/recommended-project - requires drupal/core-recommended (^9.5)

I don't understand how else I'm supposed to upgrade that package? There is currently a root requirement for ^9.5 and I want to now upgrade to ^10.1. How else should I do this?

@stof
Copy link
Contributor

stof commented Oct 19, 2023

Well, if you want to update it to 10.1, you need to update your composer.json to change the requirement.

@joachim-n
Copy link
Author

That's not my point with this issue.

Composer outputs a message that says 'Try command composer foo. But doing composer foo crashes. Composer should not give bad advice to the user.

@ktomk
Copy link
Contributor

ktomk commented Oct 20, 2023

IMHO a bit borderline to call it bad advice to try a --dry-run command, but nevertheless I like @fredden's proposal in #11691 as the require gives a different view on the problem and is exception free in this case. I tried reproducing and could, but require does not lead to an installable set in my testbed (no idea if this was considered an installable set in the first place as the report is about the suggestion message, not the dependencies.)

@joachim-n can you try with the patches from #11691 / #11692 and share how it looks from your end?

@joachim-n
Copy link
Author

IMHO a bit borderline to call it bad advice to try a --dry-run command

I think you're still missing my point. It is bad advice to recommend a specific command which will crash.

@ktomk
Copy link
Contributor

ktomk commented Oct 21, 2023

@joachim-n : Nah, just my opinion. Please apply those specific patches mentioned and report back if they specifically address your point from your point of view and any more commentary you have about those. This would allow me to better help you finding a solution for your issue.

@Seldaek
Copy link
Member

Seldaek commented Oct 26, 2023

Ok with latest snapshot the why-not command now outputs:

Not finding what you were looking for? Try calling composer require "drupal/core-recommended:^10.1" --dry-run to get another view on the problem.

So I'll call this fixed. Thanks everyone

@Seldaek Seldaek closed this as completed Oct 26, 2023
@Seldaek Seldaek added this to the 2.6 milestone Oct 26, 2023
@Seldaek Seldaek added the Bug label Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment