Problem/Motivation

Brand new clean install of 9.1.8.

First thing I do is create a new theme in themes/custom/

I create the ...

themename.info.yml
and
themename.libraries.yml

Files.

name: themename
type: theme
description: 
core: 8.x
core_version_requirement: ^8 || ^9
# Defines the base theme
base theme: stark
# Defines libraries group in which we can add css/js.
libraries:
  - themename/global-styling
  - themename/global-scripts

When I go to /admin/appearance I get a white screen error with this error.

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

I left the "description" blank, cause... I didn't think I needed it.

I sorta deduced what the problem is, and added some characters so it had SOMETHING in the Description, and the problem went away.

I think this should not have a fatal error... or at least give you some better directions. I can see entry level theme builders throwing up their hands pretty quickly with a white screen error and they don't know how to turn on verbose error messages.

Steps to reproduce

See above.

Proposed resolution

Friendlier error messages, or allow for the Description field to be blank.

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

CommentFileSizeAuthor
#11 3213079_blank_name_theme.png47.67 KBhmendes

Issue fork drupal-3213079

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

alphex created an issue. See original summary.

quietone’s picture

Component: language system » theme system
Issue tags: +Bug Smash Initiative

el7cosmos made their first commit to this issue’s fork.

el7cosmos’s picture

Probably we can throw an exception when building theme info if the description isn't a string. If a developer want an empty description, it should be with an empty string ''

el7cosmos’s picture

Status: Active » Needs review
hmendes’s picture

I think this might be duplicated from #2600462: Incorrect syntax in frontend theme .info.yml file will throw an error in the backend when clearing caches via the UI. The problem isn't with the description field specifically, any problem in the .yml file is going to break the site with an unfriendly message.

If the correct approach is to only change the errors to be friendlier, so we could create some meta issue, and fix the problems separately:

The other option I have would be specifically to this issue, to let the description to be blank...

What do you think?

el7cosmos’s picture

I don't think that is the same problem, the problem here is description: , which is valid YAML syntax, whereas the other issue is invalid YAML syntax.

The problem lies here is the parser translates the description into NULL, the description itself is optional according to https://www.drupal.org/docs/theming-drupal/defining-a-theme-with-an-info... and the default value is empty string ''.

On the appeareance page, the description is localized with t, expecting the description is string or default empty string, so in the end, the theme info always has description property, whether or not it is defined in the info.yml. But if description is defined with no value, which mean NULL, t will give an error, which left us with two options:
- Reject NULL or non-string value.
- Cast NULL to empty string.

This behavior is already present when handling base theme property in https://git.drupalcode.org/project/drupal/-/blob/9.2.x/core/lib/Drupal/C...

If we really want to handle all properties of info meta-data, along with their require/optional and data type, I think we should come up with a schema

el7cosmos’s picture

hmendes’s picture

StatusFileSize
new47.67 KB

Hi @el7cosmos, I saw here, and I understood what you said,

  • For all the optional fields, if you let blank, it doesn't happens anything.
  • For the name, it doesn't happen anything although it is required ( you have to have the field but it can be blank )
  • For the other required fields, it shows an error specific to the field (except the description field ).

So I think this is right, IMO we should cast NULL to empty string, to do something like the name field.

quietone’s picture

Version: 9.1.x-dev » 9.2.x-dev
Status: Needs review » Needs work
Issue tags: +Needs tests

Looks like this needs work for the items in #11

This will also need a test.

danflanagan8’s picture

This is essentially a duplicate of #2730807: WSOD on admin/modules if description is set but is NULL in module.info.yml. That one is for modules, but the problem is in the ExtensionList abstract class, which handles both modules and themes. They should be fixed together.

@quietone, you've commented on both recently. How do you think we should move forward?

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

Drupal 9.1.10 (June 4, 2021) and Drupal 9.2.10 (November 24, 2021) were the last bugfix releases of those minor version series. Drupal 9 bug reports should be targeted for the 9.3.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.4.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.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

Status: Needs work » Closed (duplicate)

#2730807: WSOD on admin/modules if description is set but is NULL in module.info.yml was fixed with a generic solution that fixes this too.

Feel free to re-open this if you think there is something we still need to address here.

Thanks!