Problem/Motivation

I created a custom module with a blank "description" in the modules .info.yml file.

Trying to visit the Extend / module list page shows "The website encountered an unexpected error. Please try again later." and an error in the Watchdog log:

InvalidArgumentException: $string ("") must be a string. in Drupal\Core\StringTranslation\TranslatableMarkup->__construct() (line 140 of core/lib/Drupal/Core/StringTranslation/TranslatableMarkup.php)

The problem originates at line 209 in core/modules/system/src/Form/ModulesListForm.php

    $row['description']['#markup'] = $this->t($module->info['description']);

Proposed solution is to test for $module-info['description']):

    $row['description']['#markup'] = $this->t(isset($module->info['description']) ? $module->info['description'] : '');

There might be a better way, e.g. to highlight the missing description before we get to this point, or disable the module. According to https://www.drupal.org/node/2000204 the description should be required/mandatory.

Steps to reproduce

To reproduce, create an empty module with just a module info.yml as shown below, and visit the Extend page.

name : emptytest
description :
type: module
core : 8.x

Proposed resolution

See suggestion in #23

Remaining tasks

Agree on the solution
patch with test
review
commit

User interface changes

API changes

Data model changes

Release notes snippet

Comments

versantus created an issue. See original summary.

versantus.nik’s picture

StatusFileSize
new782 bytes
versantus.nik’s picture

versantus.nik’s picture

versantus.nik’s picture

Status: Active » Needs review

Marking as Needs Review. Apologies for all of the accidental updates!

Status: Needs review » Needs work

The last submitted patch, 2: blankdescription-2730807-1.patch, failed testing.

cilefen’s picture

versantus.nik’s picture

Status: Needs work » Needs review
versantus.nik’s picture

cilefen’s picture

Issue tags: +Needs tests

Usually we add a test for something like this.

versantus.nik’s picture

Thanks, I will have a go! I think I need to write a Functional Test (based on https://api.drupal.org/api/drupal/core%21core.api.php/group/testing/8.1.x). Do you agree?

cilefen’s picture

Status: Needs review » Needs work

Try not to write a new test class. The test for the form you modified is Drupal\system\Tests\Form\ModulesListFormWebTest. Other places are Drupal\KernelTests\Core\Extension\ModuleInstallerTest or Drupal\system\Tests\Module\InstallUninstallTest. But in thinking about the patch in #2, it fixes this superficially (and I don't mean that negatively) in the UI, but if a module were enabled any other way, this would still be a problem. So in addition to a test I think we need a deeper fix. I think something at the level of module discovery would be better.

cilefen’s picture

ThemeHandler::rebuildThemeData() has a way of merging defaults. I wonder if we can do something analogous for modules.

cilefen’s picture

_system_rebuild_module_data() is supposed to do this but does not.

cilefen’s picture

Title: Cannot view module list if missing description in module.info.yml » Cannot view module list if missing description is set but is NULL in module.info.yml
Status: Needs work » Needs review
StatusFileSize
new739 bytes

This is what I meant by "deeper" in #12. However, I now realize that #2 is probably more appropriate because the form function itself is calling t() on something that may be null and that is probably its problem.

In a case like this we are talking about valid YAML with description set, but empty, which means null. It seems other parts of Drupal don't have a problem with this. But notice that the defaults array in _system_rebuild_module_data() specifies that description is an empty string, assuming it was unset.

cilefen’s picture

Title: Cannot view module list if missing description is set but is NULL in module.info.yml » WSOD on admin/modules if description is set but is NULL in module.info.yml
SidneyGijzen’s picture

Great to see that there are already multiple approaches to solving this!

Reading through this issue and your patches, I was thinking along the following lines:

  1. versantus linked to this page, where it states that a description is required
  2. cilefen stated in #16, "the defaults array in _system_rebuild_module_data() specifies that description is an empty string, assuming it unset"
  3. _system_rebuild_module_data() uses the InfoParser service to parse .yml files
  4. which in turn make use of the function getRequiredKeys (core/lib/Drupal/Core/Extension/InfoParserDynamic)
  5. however the function getRequiredKeys() doesn't define the description as a required key (which is the reason it is assumed an empty string in _system_rebuild_module_data() ?)

So, I'm wondering, does it make sense to add the description as a required key in getRequiredKeys()? Does that achieve that 'deeper fix' cilefen is looking for? And catches the error if the module is enabled in a non-GUI way?

cilefen’s picture

@MF82: While we think about this, would you like to try writing the test? You can ping me on IRC for tips.

SidneyGijzen’s picture

@cilefen: Yes, I would like to give it a try. I will first do some digging based on your pointers from #12. And, thank you!

almaudoh’s picture

I think a more generic solution for all .info.yml files where required keys are missing would be to throw a MissingRequiredInfoKeyException (or some such) which could be caught and properly displayed on the UI.

xjm’s picture

@almaudoh, I think that's a good suggestion generally. I posted your suggestion on #2558645: Malformed module.info.yml prevents install with a confusing error because I think that's the correct solution for required keys.

In this case though it's not a required key, but an incorrectly empty optional key. In #2594937: Empty 'libraries:' in theme .info.yml file produces confusing PHP warning, there is a case to support the key being present but empty for DX/TX reasons.

I also agree that it's non-ideal to go though and add isset()/!empty() checks all over the place for every individual, optional key.

alexpott’s picture

So both modules and themes have a default array to merge to the information in .info.yml - see _system_rebuild_module_data() and \Drupal\Core\Extension\ThemeHandler::rebuildThemeData(). I think it is worth considering that if the yaml value is NULL we should use the default. That would fix both #2730807: WSOD on admin/modules if description is set but is NULL in module.info.yml and #2594937: Empty 'libraries:' in theme .info.yml file produces confusing PHP warning

xjm’s picture

So I guess it might be best to postpone this issue on that followup, which would also remove the then-redundant emptiness checks for individual keys?

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jhedstrom’s picture

Status: Needs review » Postponed

Marking as postponed as suggested above. Also a test is still needed if this approach is eventually pursued.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

quietone’s picture

Assigned: versantus.nik » Unassigned
Issue summary: View changes
Status: Postponed » Active
danflanagan8’s picture

This issue is still present in 9.4.x. But there's been some serious refactoring in core since the last patch here.For example, _system_rebuild_module_data no longer exists.

Following the pattern of the related issue, which adds a little check to ThemeHandler::addTheme(), we could add a check to ModuleHandler::addModule() that does something special when the description is null.

However, the same WSOD occurs on the Appearance page if the description of a Theme is set to null. If we wanted to fix both of these at the same time I would be in favor of that. (edit: here's an issue for the appearances WSOD: #3213079: When creating a theme, if you leave the description field empty in the themename.info.yml file, it throws a white screen error)

In a comment on the related issue a follow-up was eluded to, but I don't think it was ever made. Comment #24 here even refers to "that followup", but I don't see any evidence that followup was created. From an issue queue standpoint, how should we proceed? Do we adjust this one to act as the followup? Do we close this and create a new issue from scratch?

From a code standpoint, we have some nice options.

We could add a check to Drupal\Core\Extension\InfoParserDynamic::parse(), which is used for parsing module, theme, and profile .info files.

But I think I like @alexpott's idea in #23 a little better though, which is to leverage the default values of the ExtensionList classes better. We could alter ExtensionList::createExtensionInfo() to be more clever with the default values. The current code is below. It adds default values if the keys are missing, but it won't overwrite a value of null.

  protected function createExtensionInfo(Extension $extension) {
    $info = $this->infoParser->parse($extension->getPathname());

    // Add the info file modification time, so it becomes available for
    // contributed extensions to use for ordering extension lists.
    $info['mtime'] = $extension->getMTime();

    // Merge extension type-specific defaults.
    $info += $this->defaults;

    return $info;
  }

There could be some simple code before the merge to unset any keys where the value is null. Then the default values would get used in those cases.

Update: But there's even another issue I found that wants to handle null values in TranslatableMarkup: #2719553: Log error when a TranslatableMarkup is created with a non-string input, which would make this issue moot.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

lendude’s picture

Version: 9.5.x-dev » 11.x-dev
Status: Active » Needs review
Issue tags: -Needs tests
StatusFileSize
new1.46 KB

This seems to have gotten fixed in the intervening years, this test should be green

lendude’s picture

StatusFileSize
new1.46 KB

Ah wait, not fixed, it has to be NULL to fail, see test

lendude’s picture

StatusFileSize
new1.46 KB

Ah wait, not fixed, it has to be NULL to fail, see test

Status: Needs review » Needs work

The last submitted patch, 42: 2730807-42-TEST_ONLY.patch, failed testing. View results

lendude’s picture

Status: Needs work » Needs review
StatusFileSize
new2.26 KB

Here is a fix that implements #23, no interdiff since its a different approach than previously

smustgrave’s picture

So the IS points to #21 which is to throw a MissingRequiredInfoKeyException but is it now just to display a message?

lendude’s picture

Issue summary: View changes

We can't/shouldn't throw an exception for description as if it is required, because it's not required. So the solution is now to make sure the defaults are used if something is set to NULL. I removed #21 from the IS.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Gotcha.

Verified the problem described in the IS
Edited the action module description to be description:
Got a fatal error
Applied patch #45 and no issue now.

  • catch committed d7e7f3ac on 10.1.x
    Issue #2730807 by Lendude, versantus.nik, cilefen, xjm, SidneyGijzen,...

  • catch committed b1d57de4 on 11.x
    Issue #2730807 by Lendude, versantus.nik, cilefen, xjm, SidneyGijzen,...
catch’s picture

Version: 11.x-dev » 10.1.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x and cherry-picked to 10.1.x, thanks!

lendude’s picture

Issue tags: +ddd2023

Thanks! I forgot to tag with ddd23, fixing that now.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.