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
| Comment | File | Size | Author |
|---|---|---|---|
| #48 | 2558645-48.patch | 2.55 KB | almaudoh |
| #41 | interdiff-37-41.patch | 1.44 KB | Vidushi Mehta |
| #41 | 2558645-41.patch | 2.58 KB | Vidushi Mehta |
| #37 | interdiff-29-37.txt | 1.44 KB | Vidushi Mehta |
| #37 | 2558645-37.patch | 2.53 KB | Vidushi Mehta |
Comments
Comment #2
cilefen commentedComment #3
joshi.rohit100I see this if I do not supply 'core' key -
Comment #4
cilefen commented#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.
Comment #5
david_garcia commentedI 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:
Downgraded to normal because this only affects the install process and is a very rare situation.
Comment #6
cilefen commentedComment #7
danepowell commentedThanks 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.
Comment #8
cilefen commented@Dane Powell I added that info to the issue summary.
Comment #10
almaudoh commentedI 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.
Comment #11
cilefen commentedComment #12
xjm@almaduoh made a good suggestion in #2730807: WSOD on admin/modules if description is set but is NULL in module.info.yml:
I think that is the correct solution when the key is required.
Comment #13
alexpottSo 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 warningI;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.
Comment #14
andyd328FWIW this also affects malformed info.yml files in install profiles.
Comment #15
almaudoh commentedHere's a patch with test and fix.
Comment #21
jhedstromI 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.
Comment #22
alexpottNeeds a reroll :(
Comment #23
almaudoh commentedRerolled
Comment #24
almaudoh commentedComment #25
almaudoh commentedComment #27
jhedstromThanks @almaudoh! Back to RTBC.
Comment #28
alexpottOops should have noticed... this ought to be
->addError()- it means there are less hardcoded strings about.Comment #29
almaudoh commentedOops! Missed that.
Comment #30
alexpottReally sorry for the review in drips and drabs.
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: %errorin \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: %errorComment #31
Vidushi Mehta commentedAdded a patch with a above mentioned change. Removed the quotes from error message.
Comment #32
Vidushi Mehta commentedComment #34
Vidushi Mehta commentedBut 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.
Comment #35
alexpott@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()]));Comment #36
alexpottNote you also need to update the assertion text.
Comment #37
Vidushi Mehta commentedThat's what I was thinking. Thanks @alexpott for making me correct I was also in doubt.
Added a correct patch with the changes.
Comment #39
alexpottNeed to remove the double quotes :)
Comment #40
alexpottShould 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
Comment #41
Vidushi Mehta commentedI 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.
Comment #43
Vidushi Mehta commentedComment #44
manjit.singhinterdiff should be in
.txtformat.Comment #45
jhedstromThanks @Vidushi Mehta!
Comment #48
almaudoh commentedRerolled patch. Left RTBC.
Comment #49
larowlanAdding review credits
Comment #52
larowlanCommitted as 2be3c89 and pushed to 8.7.x.
Cherry-picked as e59e83e and pushed to 8.6.x.