Crashes on leftovover themeconfig

Created on 12 May 2023, over 2 years ago

Problem/Motivation

Sometheme has been (incompletely) removed. Then config_inspector installed. Upon going to configure config_inspector crashes.

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

InvalidArgumentException: The configuration property conditions.current_theme.theme.somethemename doesn't exist. in Drupal\Core\Config\Schema\ArrayElement->get() (line 76 of core/lib/Drupal/Core/Config/Schema/ArrayElement.php).

Drupal\config_inspector\ConfigInspectorManager->checkValue() (Line: 137)
Drupal\config_inspector\ConfigInspectorManager->checkValue() (Line: 137)
Drupal\config_inspector\ConfigInspectorManager->checkValue() (Line: 137)
Drupal\config_inspector\ConfigInspectorManager->checkValue() (Line: 61)
Drupal\config_inspector\ConfigInspectorManager->checkConfigSchema() (Line: 137)
Drupal\config_inspector\ConfigInspectorManager->checkValues() (Line: 170)
Drupal\config_inspector\Controller\ConfigInspectorController->overview()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 23)
Stack\StackedHttpKernel->handle() (Line: 718)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Steps to reproduce

Proposed resolution

Report error in configuration.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇦🇹Austria maxilein

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @maxilein
  • 🇦🇹Austria maxilein

    maybe this helps https://www.drupal.org/project/drupal/issues/2925890 🐛 Invalid config structures can result in exceptions when saving a config entity Needs work

  • Status changed to Postponed: needs info over 2 years ago
  • 🇭🇺Hungary Gábor Hojtsy Hungary

    I think 📌 Config inspection should wipe relevant caches to always get up-to-date results Fixed should have helped for this? Can you check?

  • 🇦🇹Austria maxilein

    Thanky you. I tested the new release. I get the same error. And in the meantime I suspect it is a wrong config.

    My question is: since config inspector is a tool to find problems in the config, shouldn't it be able to continue on such an error and list the invalid entry instead of crashing?

  • Status changed to Needs work over 2 years ago
  • 🇭🇺Hungary Gábor Hojtsy Hungary

    It should definitely not crash on invalid config indeed. The exception comes from ArrayElement::get() in Drupal core.

      /**
       * {@inheritdoc}
       */
      public function get($name) {
        $parts = explode('.', $name);
        $root_key = array_shift($parts);
        $elements = $this
          ->getElements();
        if (isset($elements[$root_key])) {
          $element = $elements[$root_key];
    
          // If $property_name contained a dot recurse into the keys.
          while ($element && ($key = array_shift($parts)) !== NULL) {
            if ($element instanceof TypedConfigInterface) {
              $element = $element
                ->get($key);
            }
            else {
              $element = NULL;
            }
          }
        }
        if (isset($element)) {
          return $element;
        }
        else {
          throw new \InvalidArgumentException("The configuration property {$name} doesn't exist.");
        }
      }
    

    checkValues() does not document as even re-throwing an InvalidArgumentException but it is documented to rethrow SchemaIncompleteException, which it should also convert into an error to display rather than throw.

  • 🇦🇹Austria maxilein

    I don't understand where the value is expected. Where should the property exist? In the config table? In the theme yml?
    Maybe I can help more by getting more information.

  • 🇪🇸Spain aleix

    While it doesn't solve what Gábor said: @maxilein this configuration comes from asset_injector module, following steps as https://www.drupal.org/project/asset_injector/issues/3329577#comment-150... 🐛 Fatal error: Schema error for theme condition selection field Fixed helps .

  • 🇦🇹Austria maxilein

    Aleix, thank you. That makes sense! I will investigate and report here.

  • 🇦🇹Austria maxilein

    Well I am already using the latest versions of asset injector.

    What i can report about the situation: there was an old theme installed and used as default. The designer completely reworked his theme to a new version but kept the old theme name. Since there was no upgrade path the new one was copied over the old one...

    So there may be some left over configs. I will try and re-save all assets and see if that makes a difference.

  • 🇦🇹Austria maxilein

    So saved all asset injectors. There are still 2 Errors:

    Error message
    
        Warning: Undefined array key "compare_format" in Drupal\name\Plugin\diff\Field\NameFieldBuilder->build() (line 73 of modules/contrib/name/src/Plugin/diff/Field/NameFieldBuilder.php).
    
        Drupal\name\Plugin\diff\Field\NameFieldBuilder->build(Object) (Line: 94)
        Drupal\diff\DiffEntityParser->parseEntity(Object) (Line: 104)
        Drupal\diff\DiffEntityComparison->compareRevisions(Object, Object) (Line: 181)
        Drupal\elogger\Services\Elogger->entityDiff(Object) (Line: 472)
        Drupal\elogger\Services\Elogger->prepareEntityLogMessage('entity_update', Object) (Line: 532)
        Drupal\elogger\Services\Elogger->logEvent('entity_update') (Line: 73)
        _log_entity_event('entity_update', Object) (Line: 50)
        elogger_entity_update(Object)
        call_user_func_array(Object, Array) (Line: 426)
        Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object, 'elogger') (Line: 405)
        Drupal\Core\Extension\ModuleHandler->invokeAllWith('entity_update', Object) (Line: 433)
        Drupal\Core\Extension\ModuleHandler->invokeAll('entity_update', Array) (Line: 251)
        Drupal\Core\Entity\EntityStorageBase->invokeHook('update', Object) (Line: 900)
        Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('update', Object) (Line: 598)
        Drupal\Core\Entity\EntityStorageBase->doPostSave(Object, 1) (Line: 781)
        Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object, 1) (Line: 523)
        Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 804)
        Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 339)
        Drupal\Core\Entity\EntityBase->save() (Line: 46)
        Drupal\user\ProfileForm->save(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: 597)
        Drupal\Core\Form\FormBuilder->processForm('user_form', Array, Object) (Line: 325)
        Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
        Drupal\Core\Controller\FormController->getContentResult(Object, Object) (Line: 39)
        Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object, Object)
        call_user_func_array(Array, Array) (Line: 123)
        Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
        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: 169)
        Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
        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: 23)
        Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
        Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
    
        Warning: Undefined array key "compare_format" in Drupal\name\Plugin\diff\Field\NameFieldBuilder->build() (line 73 of modules/contrib/name/src/Plugin/diff/Field/NameFieldBuilder.php).
    
        Drupal\name\Plugin\diff\Field\NameFieldBuilder->build(Object) (Line: 94)
        Drupal\diff\DiffEntityParser->parseEntity(Object) (Line: 105)
        Drupal\diff\DiffEntityComparison->compareRevisions(Object, Object) (Line: 181)
        Drupal\elogger\Services\Elogger->entityDiff(Object) (Line: 472)
        Drupal\elogger\Services\Elogger->prepareEntityLogMessage('entity_update', Object) (Line: 532)
        Drupal\elogger\Services\Elogger->logEvent('entity_update') (Line: 73)
        _log_entity_event('entity_update', Object) (Line: 50)
        elogger_entity_update(Object)
        call_user_func_array(Object, Array) (Line: 426)
        Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object, 'elogger') (Line: 405)
        Drupal\Core\Extension\ModuleHandler->invokeAllWith('entity_update', Object) (Line: 433)
        Drupal\Core\Extension\ModuleHandler->invokeAll('entity_update', Array) (Line: 251)
        Drupal\Core\Entity\EntityStorageBase->invokeHook('update', Object) (Line: 900)
        Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('update', Object) (Line: 598)
        Drupal\Core\Entity\EntityStorageBase->doPostSave(Object, 1) (Line: 781)
        Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object, 1) (Line: 523)
        Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 804)
        Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 339)
        Drupal\Core\Entity\EntityBase->save() (Line: 46)
        Drupal\user\ProfileForm->save(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: 597)
        Drupal\Core\Form\FormBuilder->processForm('user_form', Array, Object) (Line: 325)
        Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
        Drupal\Core\Controller\FormController->getContentResult(Object, Object) (Line: 39)
        Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object, Object)
        call_user_func_array(Array, Array) (Line: 123)
        Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
        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: 169)
        Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
        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: 23)
        Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
        Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
    
    
  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Is there an open issue to catch that in core and return an unknown error?

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Found 🐛 Invalid config structures can result in exceptions when saving a config entity Needs work but that seems like its not addressing the issue in the schema check trait, which I would have expected

    I'll open a new issue

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Ah! the issue is we had the patch (comment 29) from the above issue applied

  • 🇪🇸Spain guiu.rocafort.ferrer Barcelona

    guiu.rocafort.ferrer made their first commit to this issue’s fork.

  • Pipeline finished with Manual
    7 months ago
    #440771
  • 🇪🇸Spain guiu.rocafort.ferrer Barcelona

    I've approached the issue catching the Exception from SchemaCheckTrait::checkConfigSchema and returning an array with the error message from that exception in checkValues.

  • 🇳🇱Netherlands roderik Amsterdam,NL / Budapest,HU

    I came here from 🐛 Expected argument of type "array", "string" given Active and this MR inspired me to make a MR there. (The code is different: this one catches a crash in checkValues(); #3444730 catches a crash in validateValues().)

    While I have not reproduced this... I think it you can probably argue that

    • this does not need tests at all, because we can/should just assume that
      • checkConfigSchema() can throw any old exception
      • and checkValues() just needs to take care of those and never choke
    • ...so all you need to do is check the phpcs error and then set to review without tests?

    I admit that this in my validateValues() case, that is clearer to me than for this MR. (Because this calls checkConfigSchema(), which I don't know, whereas my case calls Typed Data stuff, which is "urgh, scary black box, we must be prepared to handle any exception that could throw".)

  • 🇪🇸Spain guiu.rocafort.ferrer Barcelona

    Hi @roderik! Thanks for your comments.

    I believe there are ( at least ) three methods that throw exceptions that are not handled in the validateValues method.

    1. $this->checkValues($config_name) can throw the following exceptions:
    InvalidArgumentException ( it does that in several classes extending TypedData class ).
    MissingDataException ( some classes extending TypedData class ).

    2. typedConfigManager->getDefinition can throw the following exceptions:
    PluginNotFoundException

    3. TypedData->validate can throw the following exceptions:
    LogicException
    UnexpectedTypeException
    InvalidArgumentException ( not sure if it is really thrown, since it might not execute because the checkValues would fail ).
    MissingDataException ( not sure if it is really thrown, since it might not execute because the checkValues would fail ).

    The phpdoc for the validateValues method claims it can throw a SchemaIncompleteException, although i am not sure where that would come from.

    In summary: The exceptions in those three methods should be handled in the validateValues, and appropiate errors returned. Because there are so many types of exceptions, and there are not really well documented in the phpdoc comments for the methods, i think we might just catch all the Exceptions for now to be sure we don't miss anything, although i am aware this is not really a good practice...

    I think this should allow to close a few similar issues already existing:
    https://www.drupal.org/project/config_inspector/issues/3444730 🐛 Expected argument of type "array", "string" given Active
    https://www.drupal.org/project/config_inspector/issues/3456858 🐛 The LangcodeRequiredIfTranslatableValues constraint can only operate on the root object being validated. Needs work

  • 🇪🇸Spain guiu.rocafort.ferrer Barcelona

    Removing the needs test tag, think @roderik is right.

  • Pipeline finished with Manual
    7 months ago
    #442722
  • Pipeline finished with Manual
    6 months ago
    #452307
  • 🇭🇺Hungary Gábor Hojtsy Hungary

    Anyone tested the suggested changes? :)

  • Status changed to Needs review 16 days ago
  • 🇩🇪Germany akoe

    Just ran into a similar Exception thrown at route admin/reports/config-inspector

    Drupal\Component\Plugin\Exception\PluginNotFoundException: The "GreaterThan" plugin does not exist. Valid plugin IDs for Drupal\Core\Validation\ConstraintManager are...
    

    Which is exception type number 2 mentioned in #18
    Call stack:

    Drupal\Core\Plugin\DefaultPluginManager->getDefinition() (Line: 21)
    Drupal\Core\Validation\ConstraintFactory->createInstance() (Line: 83)
    Drupal\Component\Plugin\PluginManagerBase->createInstance() (Line: 86)
    Drupal\Core\Validation\ConstraintManager->create() (Line: 123)
    Drupal\Core\TypedData\TypedData->getConstraints() (Line: 45)
    Drupal\Core\TypedData\Validation\TypedDataMetadata->getConstraints() (Line: 38)
    Drupal\Core\TypedData\Validation\TypedDataMetadata->findConstraints() (Line: 152)
    Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateNode() (Line: 164)
    Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateNode() (Line: 106)
    Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validate() (Line: 93)
    Drupal\Core\TypedData\Validation\RecursiveValidator->validate() (Line: 132)
    Drupal\Core\TypedData\TypedData->validate() (Line: 355)
    Drupal\config_inspector\ConfigInspectorManager->validateValues() (Line: 176)
    Drupal\config_inspector\Controller\ConfigInspectorController->overview()
    call_user_func_array() (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 638)
    Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 54)
    Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle() (Line: 53)
    Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
    Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 116)
    Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
    Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 741)
    Drupal\Core\DrupalKernel->handle() (Line: 19)
    require('/home/project/app/index.php') (Line: 4)

    The changes from MR #23 solved the uncatched exception and i left a comment on the MR for some leftover use statement in src/ConfigInspectorManager.php line 9

  • Pipeline finished with Failed
    16 days ago
    Total: 582s
    #589758
  • Pipeline finished with Failed
    16 days ago
    Total: 774s
    #589762
  • Pipeline finished with Manual
    16 days ago
    #589773
Production build 0.71.5 2024