Problem/Motivation

The module admin page /admin/modules is not resilient and easily breaks once a module contains a malformed info.yml file or the info.yml is missing the "core" attribute.

Such a situation should not completely take a site down. Furthermore, the error that is displayed is not helpful and provides no information to help diagnose and fix the problem.

An example fatal error that is displayed:

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

Another example from #7:

I had the same problem after copying the standard profile and simply removing the d.o packaging info. I would have never traced it down without being able to Google it.

This definitely affects UX for site-builders and developers.

Proposed resolution

Catch the malformed *.info.yml error InfoParserException and display a useful message to the user.

Remaining tasks

Patch
Reviews
Commit

User interface changes

The module listing form will not show any modules if there is a module with broken or flawed *.info.yml file. An useful error message will however be displayed.
This is an improvement from the current WSOD which is what HEAD offers.

API changes

None

Data model changes

None

Comments

david_garcia created an issue. See original summary.

cilefen’s picture

Status: Needs work » Active
joshi.rohit100’s picture

I see this if I do not supply 'core' key -

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

Drupal\Core\Extension\InfoParserException: Missing required keys (core) in modules/pp/pp.info.yml. in Drupal\Core\Extension\InfoParser->parse() (line 45 of core/lib/Drupal/Core/Extension/InfoParser.php).

cilefen’s picture

#3 seems pretty clear to me if we are just talking about the 'core' key.

@david_garcia: Could you add an example malformed yml to the issue summary please?

This may need a title update and a refocus onto simply the malformed aspect, if incomplete files are handled with an appropriate error.

david_garcia’s picture

Priority: Major » Normal

I just tested this on an installed system and the errors are meaningful.

The issue is happening on an uninstalled system when accesing core/install.php

If a module has a malformed info file (just type in random data that not conforms to YAML) this is what you get:

Fatal error: Call to undefined function Drupal\Core\Render\system_page_attachments() in D:\d8\core\lib\Drupal\Core\Render\BareHtmlPageRenderer.php on line 70

Downgraded to normal because this only affects the install process and is a very rare situation.

cilefen’s picture

Title: Incomplete or Malformed module.info.yml file breaks down system » Malformed module.info.yml prevents install with a confusing error
Component: bootstrap system » install system
danepowell’s picture

Thanks for posting the full text of the error... I had the same problem after copying the standard profile and simply removing the d.o packaging info. I would have never traced it down without being able to Google it.

cilefen’s picture

Component: install system » extension system
Issue summary: View changes
Issue tags: +DX (Developer Experience)

@Dane Powell I added that info to the issue summary.

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

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

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

almaudoh’s picture

Issue tags: +D8UX usability

I wanted to raise a similar issue, but found this after a search. Right now the admin/modules page goes WSOD with no useful message if a module happens to miss one of the required .info.yml keys (e.g. core: 8.x).

I think a better UX would be to display this error on the UI rather than crashing the whole admin->extend interface.

xjm’s picture

@almaduoh made a good suggestion in #2730807: WSOD on admin/modules if description is set but is NULL in module.info.yml:

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.

I think that is the correct solution when the key is required.

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

I;ve moved this comment to the related issues. For this specific issue throwing an exception is exactly what we want to do. We just need to catch it in the UI.

andyd328’s picture

FWIW this also affects malformed info.yml files in install profiles.

almaudoh’s picture

Status: Active » Needs review
StatusFileSize
new1.23 KB
new2.45 KB

Here's a patch with test and fix.

The last submitted patch, 15: 2558645-15-fail.patch, failed testing.

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 » Reviewed & tested by the community

I think the fix in #15 is appropriate, and has a great test! I've re-queued for testing, but marking RTBC assuming it comes back green.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

Needs a reroll :(

almaudoh’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new1.32 KB
new2.56 KB

Rerolled

almaudoh’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update
almaudoh’s picture

Issue summary: View changes

The last submitted patch, 23: 2558645-23-fail.patch, failed testing. View results

jhedstrom’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @almaudoh! Back to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/system/src/Form/ModulesListForm.php
@@ -143,8 +144,14 @@ public function buildForm(array $form, FormStateInterface $form_state) {
+      $this->messenger()->addMessage($this->t('Modules could not be listed due to an error: "%error"', ['%error' => $e->getMessage()]), 'error');

Oops should have noticed... this ought to be ->addError() - it means there are less hardcoded strings about.

almaudoh’s picture

Status: Needs work » Needs review
StatusFileSize
new772 bytes
new2.55 KB

Oops! Missed that.

alexpott’s picture

Status: Needs review » Needs work

Really sorry for the review in drips and drabs.

+++ b/core/modules/system/src/Form/ModulesListForm.php
@@ -143,8 +144,14 @@ public function buildForm(array $form, FormStateInterface $form_state) {
+      $this->messenger()->addError($this->t('Modules could not be listed due to an error: "%error"', ['%error' => $e->getMessage()]));

quoting the error message is probably not necessary because there is the colon. The % will format with a em in the UI. There is precedence of message: %error in \Drupal\Core\Database\Install\Tasks::$tasks.

Also the message should be in the present. I.e.
Modules can not be listed due to an error: %error

Vidushi Mehta’s picture

StatusFileSize
new2.53 KB
new648 bytes

Added a patch with a above mentioned change. Removed the quotes from error message.

Vidushi Mehta’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 31: 2558645-31.patch, failed testing. View results

Vidushi Mehta’s picture

But still confused because $this->t is a function so if we remove quotes from message then how this be recognized as a string? May be my patch is not correct in terms of this.

alexpott’s picture

@Vidushi Mehta I meant to remove the double quotes from around %error. Ie. the final code should look like:
$this->messenger()->addError($this->t('Modules can not be listed due to an error: %error', [%error => $e->getMessage()]));

alexpott’s picture

+++ b/core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php
@@ -51,4 +51,29 @@ public function testModuleListForm() {
+      ->pageTextContains('Modules could not be listed due to an error: "Missing required keys (core) in ' . $path . '/broken.info.yml"');

Note you also need to update the assertion text.

Vidushi Mehta’s picture

Status: Needs work » Needs review
StatusFileSize
new2.53 KB
new1.44 KB

That's what I was thinking. Thanks @alexpott for making me correct I was also in doubt.
Added a correct patch with the changes.

Status: Needs review » Needs work

The last submitted patch, 37: 2558645-37.patch, failed testing. View results

alexpott’s picture

+++ b/core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php
@@ -70,7 +70,7 @@
+      ->pageTextContains('Modules can not be listed due to an error: "Missing required keys (core) in ' . $path . '/broken.info.yml"');

Need to remove the double quotes :)

alexpott’s picture

+++ b/core/modules/system/src/Form/ModulesListForm.php
@@ -141,8 +142,14 @@ public function buildForm(array $form, FormStateInterface $form_state) {
+      $this->messenger()->addError($this->t('Modules can not be listed due to an error: %error', [%error => $e->getMessage()]));

Should be $this->messenger()->addError($this->t('Modules can not be listed due to an error: %error', ['%error' => $e->getMessage()]));

@Vidushi Mehta it's a really good idea to test your code locally before uploading a patch. Also to learn how to run the PHPUnit test too. See https://www.drupal.org/docs/8/phpunit/running-phpunit-tests

Vidushi Mehta’s picture

Status: Needs work » Needs review
StatusFileSize
new2.58 KB
new1.44 KB

I dont know what's going wrong. I've tested it on my local and patch is applying properly.
Added another with checking it on locally. @alexpott Thanks for making me correct again :) Hope this time it works.

Status: Needs review » Needs work

The last submitted patch, 41: interdiff-37-41.patch, failed testing. View results

Vidushi Mehta’s picture

Status: Needs work » Needs review
manjit.singh’s picture

interdiff should be in .txt format.

jhedstrom’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @Vidushi Mehta!

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.

The last submitted patch, 41: 2558645-41.patch, failed testing. View results

almaudoh’s picture

StatusFileSize
new2.55 KB

Rerolled patch. Left RTBC.

larowlan’s picture

Adding review credits

  • larowlan committed 2be3c89 on 8.7.x
    Issue #2558645 by almaudoh, Vidushi Mehta, alexpott: Malformed module....

  • larowlan committed e59e83e on 8.6.x
    Issue #2558645 by almaudoh, Vidushi Mehta, alexpott: Malformed module....
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed as 2be3c89 and pushed to 8.7.x.

Cherry-picked as e59e83e and pushed to 8.6.x.

Status: Fixed » Closed (fixed)

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