- 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 1:29pm 23 May 2023 - ๐ญ๐บ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 6:27am 25 May 2023 - ๐ญ๐บ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.
- Merge request !23Draft: Issue #3359846: Catch SchemaIncompleteException from checkConfigSchema method. โ (Open) created by guiu.rocafort.ferrer
- ๐ช๐ธ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 invalidateValues()
.)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".)
- this does not need tests at all, because we can/should just assume that
- ๐ช๐ธ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:
PluginNotFoundException3. 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.