Crashes on leftovover themeconfig

Created on 12 May 2023, almost 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 almost 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 almost 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
    about 1 month 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
    about 1 month ago
    #442722
  • Pipeline finished with Manual
    19 days ago
    #452307
  • ๐Ÿ‡ญ๐Ÿ‡บHungary Gรกbor Hojtsy Hungary

    Anyone tested the suggested changes? :)

Production build 0.71.5 2024