[upstream] Handle "Composer not found" error better in ComposerExecutableValidator

Created on 16 November 2022, over 1 year ago
Updated 17 August 2023, 10 months ago

Problem/Motivation

Similar to #3320836: Handle runtime error correctly in ComposerExecutableValidator β†’ , we get a rather ugly, overwhelming "Update readiness check" error message on the Status page (below) when the Composer executable is specified in settings.php but can't be found. This issue is distinct from the other (sort of?) in that the help message appended in this case is appropriate.

The command "'/usr/bin/composer' '--version'" failed. Exit Code: 127(Command not found) Working directory: /var/www/html Output: ================ Error Output: ================ sh: 1: exec: /usr/bin/composer: not found See the help page for information on how to configure the path to Composer.

Steps to reproduce

Set the path to Composer in settings.php to anything that doesn't exist, e.g.,

$config['package_manager.settings']['executables']['composer'] = '/dev/null';

Proposed resolution

This may be tricky to pull off because it's the same exception being thrown here (\PhpTuf\ComposerStager\Domain\Exception\RuntimeException) as in #3320836: Handle runtime error correctly in ComposerExecutableValidator β†’ . If necessary, it's possible we could add more specific exception codes in Composer Stager (something I've kind of wanted to do anyway).

<!--<h3 id="summary-remaining-tasks">Remaining tasks</h3>-->
πŸ› Bug report
Status

Needs work

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States TravisCarden

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA
  • Assigned to tedbow
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    I think this might be closeable as outdated after πŸ“Œ Add a validate() method to ComposerInspector to ensure that Composer is usable Fixed because:

    • ComposerExecutableValidator is (nearly) gone; all it does is add a nice help link.
    • If Composer is not found, the error message from the ComposerIsAvailable precondition is bubbled up.

    So when this is improved in Composer Stager, we'll automatically inherit the fix, it sounds like.

    Leaving open and assigned to @tedbow for confirmation that we can close this.

  • πŸ‡§πŸ‡ͺBelgium Wim Leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    +1

  • Status changed to RTBC over 1 year ago
  • πŸ‡§πŸ‡ͺBelgium Wim Leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Reflecting #15 more clearly 😊

  • Status changed to Postponed over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

    This should postponed on Provide meaningful exception codes Β· Issue #71 Β· php-tuf/composer-stager.

    We need to confirm it actually has a better message when this is done

  • πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA
    1. Also since we expect a different message when Composer is not found we should have test for that.

      As of now we are stilling getting this ugly messages

    2. Related for some reason my web server locally cannot find Composer.

      If install Automatic Updates with $config['package_manager.settings']['executables']['composer'] = '/usr/local/bin/composer4'; set in settings.php to incorrect value I will get the messages above on installation.

      But if install Automatic Updates with no value set in settings.php I get this hard error.

      I assume anyone who tried to install Auto Updates and they didn't have access to Composer on their hosting would have this same messages

      This needs a follow-up should be core-mvp for Automatic Updates. So setting to Needs Work until the follow-up is made.

      The website encountered an unexpected error. Please try again later.

      PhpTuf\ComposerStager\Domain\Exception\LogicException: The "composer" executable cannot be found. Make sure it's installed and in the $PATH. in PhpTuf\ComposerStager\Infrastructure\Service\Finder\ExecutableFinder->find() (line 25 of vendor/php-tuf/composer-stager/src/Infrastructure/Service/Finder/ExecutableFinder.php).
      Drupal\package_manager\ExecutableFinder->find('composer') (Line: 67)
      PhpTuf\ComposerStager\Infrastructure\Service\ProcessRunner\AbstractRunner->findExecutable() (Line: 51)
      PhpTuf\ComposerStager\Infrastructure\Service\ProcessRunner\AbstractRunner->run(Array, Object) (Line: 253)
      Drupal\package_manager\ComposerInspector->getVersion('/Users/ted.bowman/sites/au-contrib') (Line: 123)
      Drupal\package_manager\ComposerInspector->validate('/Users/ted.bowman/sites/au-contrib') (Line: 195)
      Drupal\package_manager\ComposerInspector->getConfig('allow-plugins', '/Users/ted.bowman/sites/au-contrib') (Line: 165)
      Drupal\package_manager\Validator\ComposerPluginsValidator->validate(Object, 'Drupal\package_manager\Event\StatusCheckEvent', Object)
      call_user_func(Array, Object, 'Drupal\package_manager\Event\StatusCheckEvent', Object) (Line: 111)
      Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object) (Line: 45)
      Drupal\automatic_updates\Validation\StatusChecker->runStatusCheck(Object, Object) (Line: 72)
      Drupal\automatic_updates\Validation\StatusChecker->run() (Line: 204)
      automatic_updates_modules_installed(Array, )
      call_user_func_array(Object, Array) (Line: 409)
      Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object, 'automatic_updates') (Line: 388)
      Drupal\Core\Extension\ModuleHandler->invokeAllWith('modules_installed', Object) (Line: 416)
      Drupal\Core\Extension\ModuleHandler->invokeAll('modules_installed', Array) (Line: 373)
      Drupal\Core\Extension\ModuleInstaller->install(Array, 1) (Line: 83)
      Drupal\Core\ProxyClass\Extension\ModuleInstaller->install(Array) (Line: 502)
      Drupal\system\Form\ModulesListForm->submitForm(Array, Object)
      call_user_func_array(Array, Array) (Line: 114)
      Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
      Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 595)
      Drupal\Core\Form\FormBuilder->processForm('system_modules', Array, Object) (Line: 323)
      Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
      Drupal\Core\Controller\FormController->getContentResult(Object, Object)
      call_user_func_array(Array, Array) (Line: 123)
      Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 583)
      Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
      Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
      Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 163)
      Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 74)
      Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
      Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
      Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
      Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
      Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
      Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
      Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
      Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 680)
      Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
      require('/Users/ted.bowman/sites/au-contrib/index.php') (Line: 234)

    3. This same situation does not happen with Package Manager because without another module that depends on installed the status checks will not be run but I would think that any module that used would run into this same problem

      I confirmed this by installing package_manager_test_api and going to /package-manager-test-api. This same error happens

      I confirmed that if reload /package-manager-test-api with even a wrong value for $config['package_manager.settings']['executables']['composer']

      The error changes to

      The website encountered an unexpected error. Please try again later.

      Drupal\package_manager\Exception\StageValidationException: The command "'/usr/local/bin/composer4' '--format=json' '--working-dir=/Users/ted.bowman/sites/au-contrib'" failed. Exit Code: 126(Invoked command cannot execute) Working directory: /Users/ted.bowman/sites/au-contrib Output: ================ Error Output: ================ sh: /usr/local/bin/composer4: No such file or directory sh: line 0: exec: /usr/local/bin/composer4: cannot execute: No such file or directory See the help page β†’ for information on how to configure the path to Composer. Unable to determine Composer secure-http setting. The command "'/usr/local/bin/composer4' '--format=json' '--working-dir=/Users/ted.bowman/sites/au-contrib'" failed. Exit Code: 126(Invoked command cannot execute) Working directory: /Users/ted.bowman/sites/au-contrib Output: ================ Error Output: ================ sh: /usr/local/bin/composer4: No such file or directory sh: line 0: exec: /usr/local/bin/composer4: cannot execute: No such file or directory Unable to determine Composer allow-plugins setting. The command "'/usr/local/bin/composer4' '--format=json' '--working-dir=/Users/ted.bowman/sites/au-contrib'" failed. Exit Code: 126(Invoked command cannot execute) Working directory: /Users/ted.bowman/sites/au-contrib Output: ================ Error Output: ================ sh: /usr/local/bin/composer4: No such file or directory sh: line 0: exec: /usr/local/bin/composer4: cannot execute: No such file or directory in Drupal\package_manager\Stage->dispatch() (line 528 of modules/automatic_updates/package_manager/src/Stage.php).
      Drupal\package_manager\Stage->create() (Line: 151)
      Drupal\package_manager_test_api\ApiController->createAndApplyStage(Object) (Line: 96)
      Drupal\package_manager_test_api\ApiController->run(Object)
      call_user_func_array(Array, Array) (Line: 123)
      Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 583)
      Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
      Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
      Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 163)
      Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 74)
      Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
      Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
      Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
      Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
      Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
      Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
      Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
      Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 680)
      Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
      require('/Users/ted.bowman/sites/au-contrib/index.php') (Line: 234)

      So it seems 1 is handled by our status checker and 1 is not.

      So either need to handle that problem in this issue make a core-mvp Package Manager issue for this

  • Issue was unassigned.
  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA
  • πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA
  • πŸ‡ΊπŸ‡ΈUnited States xjm
Production build 0.69.0 2024