give a clearer error when config translation can't find the routes for a config entity type

Created on 3 May 2019, about 5 years ago
Updated 4 April 2023, about 1 year ago

Problem/Motivation

There are LOTS of bug reports in contrib for this crash in the translation system:

> Call to a member function getPath() on null in /core/modules/config_translation/src/ConfigNamesMapper.php on line 233

It's a confusing error, because it's actually caused by a missing route definition.

Steps to reproduce

It's really easy to cause this if you don't set up your config entity type properly. One way to do it is to define the 'field_ui_base_route' annotation property on an entity type, but not actually define the route elsewhere. Then run drush cr.

Proposed resolution

Adding a check to ConfigNamesMapper that the route exists and throwing an exception if it doesn't would be a big help to developers who hit this error, as currently it's really confusing and doesn't give you any indication of what's wrong. An exception that says which route name could not be found tells developers exactly where the problem is.

๐Ÿ“Œ Task
Status

Needs work

Version

10.1 โœจ

Component
Config translationย  โ†’

Last updated about 1 month ago

Created by

๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom joachim

Live updates comments and jobs are added and updated live.
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 smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request โ†’ as a guide.

    The issue summary should be updated with steps to reproduce. Recommend the default template as it's easier for everyone involved.

  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom joachim

    Done.

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Trying to follow the steps in the issue summary.
    In Term.php I edited field_ui_base_route by adding some random text (entity.taxonomy_vocabulary.overview_formdfdasfads.
    Going to the taxonomy page I get
    Symfony\Component\Routing\Exception\RouteNotFoundException: Route "entity.taxonomy_term.field_ui_fields" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 206 of core/lib/Drupal/Core/Routing/RouteProvider.php).

    Apply the patch
    Clear cache
    I get the same message

    Missing a step?

  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom joachim

    > In Term.php I edited field_ui_base_route by adding some random text (entity.taxonomy_vocabulary.overview_formdfdasfads.

    It's config entities that this affects, sorry! Updated the IS.

  • Status changed to RTBC over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Thanks @joachim for the clarifying!

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone New Zealand

    I closed ๐Ÿ› Useless exception "Error: Call to a member function getPath() on null" Closed: duplicate as a duplicate and am moving credit.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany geek-merlin Freiburg, Germany
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom joachim

    > Why isn't this also throwing an exception if $this->routeProvider->getRouteByName($name) doesn't find anything?

    The check of if (empty($route)) { covers that case doesn't it?

    > Also if the current error only shows up in config_translation, this feels like it might cause an exception in some cases that currently don't have one as opposed to just replacing one fatal with another. Should it be an assert() instead of an exception?

    getBaseRoute() doesn't document that it can return empty.

    Code that calls is should be already assuming it's always returning a route.

  • ๐Ÿ‡จ๐Ÿ‡ณChina qiutuo

    I also reproduced the above error in another scenario,
    When I use the ECK module to create the content entity type, the above error is thrown after the entity type is deleted,
    After using: 3052404-21.patch the following error occurs,
    Symfony\Component\Routing\Exception\RouteNotFoundException: Route "entity.field_config.weixin_field_edit_form" does not exist. in Drupal\config_translation\ConfigNamesMapper->getBaseRoute() (line 209 of core/modules/config_translation/src/ConfigNamesMapper.php).

    In fact, the entity type no longer exists, and the "entity.field_config.weixin_field_edit_form" route does not exist, but the prompt says that there is no such route.

  • ๐Ÿ‡จ๐Ÿ‡ณChina qiutuo

    I also reproduced the above error in another scenario,
    When I use the ECK module to create the content entity type, the above error is thrown after the entity type is deleted,
    After using: 3052404-21.patch the following error occurs,
    Symfony\Component\Routing\Exception\RouteNotFoundException: Route "entity.field_config.weixin_field_edit_form" does not exist. in Drupal\config_translation\ConfigNamesMapper->getBaseRoute() (line 209 of core/modules/config_translation/src/ConfigNamesMapper.php).

    In fact, the entity type no longer exists, and the "entity.field_config.weixin_field_edit_form" route does not exist, but the prompt says that there is no such route.

  • ๐Ÿ‡ท๐Ÿ‡บRussia Niklan Russia, Perm

    Hello folks, I believe that actual problem for this issue and similar to it, not in a ConfigNameMapper itself, but in container rebuild process. Please, take a look at ๐Ÿ› Update container namespaces reference instead of hard set Needs work , because it also fixes this kind of problems.

    It fails on missing route because it's working with not existing entity types in config_translation_config_translation_info().

    E.g.:

    1. Enable config translation module.
    2. Enable any module which provides a ConfigEntityType with edit-form link template.
    3. Try to disable it.
    4. You will get this error, because config_translation_config_translation_info() works with an old list of definitions. This is because entity type manager will also receive namespace of disabled module in discovery, will find entity definition and provide links for it.
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom joachim

    @Niklan it's possible that happens, but I was getting this error with the MUCH simpler way of being stupid and forgetting to define 'field_ui_base_route' in my entity type annotation!

  • ๐Ÿ‡ท๐Ÿ‡บRussia Niklan Russia, Perm

    Ah, I see. But I've got same problem with valid entity definitions (yes, multiple times with different modules), just because config translation received entity type, which is uninstalled already. This is because namespace was still presented in definitions of EntityTypeManager at the moment when the hook is called.

    If someone has the same issue as mine, you can use a temporary workaround:

    /**
     * Implements hook_config_translation_info_alter().
     */
    function module_config_translation_info_alter(array &$info): void {
      unset($info['rdf_mapping']);
    }
    
    

    I couldn't disable rdf module from core which provides a valid config entity type rdf_mapping. So I remove it from config translation logic to simply disable it.

    The symptoms of this is the same:

     Error: Call to a member function getPath() on null in Drupal\config_translation\ConfigNamesMapper->getOverviewRoute() (line 248 of /var/www/html/web/core/modules/config_translation/src/ConfigNamesMapper.php) #0 /var/www/html/web/core/modules/config_translation/src/Routing/RouteSubscriber.php(39): Drupal\config_translation\ConfigNamesMapper->getOverviewRoute()
    

    But in this case problem in container rebuild process.

    So it's actually very easy to reproduce in different ways. ๐Ÿ˜† Workaround from this issue should also help with cases like mine, btw.

Production build 0.69.0 2024