Problem/Motivation

message log shows this exception, and website display error and to fix it we run drush cache rebuild

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

je1 created an issue. See original summary.

je1’s picture

Running multisite on one installation. Some of the sites show this error and some don't, is there a way to clean up optimized on sites that show this error to force it to re-optimize CSS?

PHP 7.3.16
Server version: Apache/2.4.6 (CentOS)
CentOS Linux release 7.7.1908 (Core)

cilefen’s picture

Component: CSS » asset library system
larowlan’s picture

Category: Bug report » Support request
Issue tags: +Bug Smash Initiative

Is it possible one of your library.yml files inadvertently lists a non CSS file, eg a sass, pcss or js file instead

Can you debug which file causes the notice

je1’s picture

searched for sass, pcss, and js. found only one

/var/www/drupal$ find *library.yml | xargs grep -i js
./core/modules/media_library/config/install/views.view.media_library.yml: row_class: 'media-library-item media-library-item--table js-media-library-item js-click-to-select'

larowlan’s picture

Do you have any custom themes or modules on this site?

This error occurs if you attempt to optimize a css entry from a libraries.yml where the css entry is e.g. a URI and not a file

je1’s picture

We use theme gavias_tico and there is file called gavias_tico.libraries.yml

larowlan’s picture

Do you get the same issue with a different theme?

That theme isn't available on Drupal.org, so I assume is custom.

The issue is likely in the libraries file in that theme.

je1’s picture

We use the same theme for multiple website subdomains, the exception shows up on two of them but not the others. Have not tried using other theme to check.

The exception log messages show different pages url locations

Exception: Only file CSS assets can be optimized. in Drupal\Core\Asset\CssOptimizer->optimize() (line 25 of /var/www/drupal/core/lib/Drupal/Core/Asset/CssOptimizer.php).

je1’s picture

StatusFileSize
new3 KB
larowlan’s picture

Try adding `preprocess: false` to the Google font entries

je1’s picture

Like this?

css:
theme:
//fonts.googleapis.com/css?family=Raleway:400,600,700,800,900: { type: external, preprocess: false }
//fonts.googleapis.com/css?family=Open+Sans:400,600,700,800: { type: external, preprocess: false }

larowlan’s picture

Yeah

je1’s picture

That didn't fix it.

je1’s picture

Before the exception, there are about 10 notices like this one:

Notice: Undefined index: type in Drupal\Core\Asset\CssOptimizer->optimize() (line 24 of /var/www/drupal/core/lib/Drupal/Core/Asset/CssOptimizer.php)
#0 /var/www/drupal/core/includes/bootstrap.inc(600): _drupal_error_handler_real(8, 'Undefined index...', '/var/www/drupal...', 24, Array)

je1’s picture

And 2 warnings like this:

Warning: ksort() expects parameter 1 to be array, null given in Drupal\advagg_bundler\Asset\AdvaggCssCollectionGrouper->group() (line 62 of /var/www/drupal/modules/advagg/advagg_bundler/src/Asset/AdvaggCssCollectionGrouper.php)
#0 /var/www/drupal/core/includes/bootstrap.inc(600): _drupal_error_handler_real(2, 'ksort() expects...', '/var/www/drupal...', 62, Array)
#1 [internal function]: _drupal_error_handler(2, 'ksort() expects...', '/var/www/drupal...', 62, Array)

larowlan’s picture

Does this occur if adv_agg is turned off

je1’s picture

Notice: Undefined index: weight in Drupal\Core\Asset\AssetResolver::sort() (line 386 of /var/www/drupal/core/lib/Drupal/Core/Asset/AssetResolver.php)
#0 /var/www/drupal/core/includes/bootstrap.inc(600): _drupal_error_handler_real(8, 'Undefined index...', '/var/www/drupal...', 386, Array)
#1 /var/www/drupal/core/lib/Drupal/Core/Asset/AssetResolver.php(386): _drupal_error_handler(8, 'Undefined index...', '/var/www/drupal...', 386, Array)

je1’s picture

Just to make sure, you mean to uncheck "Enable advanced aggregation"

Administration > Configuration > Development > Performance

larowlan’s picture

Yes, sorry

je1’s picture

That didn't fix it.

je1’s picture

Just food for thought

Is there a way to clear CSS Optimizer data or all optimized data and force it to start the optimize process from the beginning?

or may be add logger line of code in the optimizer to tell us where it is coming from?

je1’s picture

website shows

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

je1’s picture

To reproduce on production site,

Fill contact us form and submit or login as admin. After that the contact form and login will show "Try again ..." until drush -cr

Any ideas?

cilefen’s picture

@je1 Is that starting from "Install Drupal"? Because much of Drupal core has test coverage I think there is something else we would need to reproduce the issue.

je1’s picture

StatusFileSize
new9.32 KB

Thanks for the help,

Yes, that is started with first install of drupal 8.

Attached is enabled modules list

cilefen’s picture

je1’s picture

It is not that one, tried disabling css injector preprocessing like it says last week and that didn't fix it.

Started seeing this error after moving from D7 to D8 last year and thought it will go away once D8 gets updated with fixes.

We have one website sub-domain running on same code base and configuration, it doesn't show that error. May be something in database or some files under file system folder /files that causing it, like gz files under css/js but don't know much about how the optimizer works. All these files have recent dates though.

Disabled cron tasks and that didn't fix it.

Researched but there is not much found other than #3169757 and few other comments.

cilefen’s picture

Have you tried adding logging to reveal which asset causes this?

je1’s picture

You mean to change line 25 of /var/www/drupal-8.9.11/core/lib/Drupal/Core/Asset/CssOptimizer.php

public function optimize(array $css_asset) {
if ($css_asset['type'] != 'file') {
throw new \Exception('Only file CSS assets can be optimized.');
}

to

public function optimize(array $css_asset) {
if ($css_asset['type'] != 'file') {

\Drupal::logger('module')->notice($css_asset);

throw new \Exception('Only file CSS assets can be optimized.');
}

Will that work? not sure what module, or you have better lines of code to add?

cilefen’s picture

Yes. But careful: $css_asset is an array so you'll have to pass something like print_r($css_asset, TRUE) to ->notice(). Use something more unique for the 'module' string so you will notice this. Perhaps raise the log level above notice.

je1’s picture

Here is the $css_asset array

Array ( [group] => 999 [browsers] => )

je1’s picture

StatusFileSize
new4.37 KB
cilefen’s picture

As I suspected above, this is very likely Asset Injector module so this will be a duplicate of #3169757: WSOD and Uncaught PHP Exception Exception: "Only file CSS assets can be optimized.".

je1’s picture

StatusFileSize
new140.94 KB

We disabled the CSS preprocessing for Asset Injector and it didn't fix it.

Configuration -> Development -> Asset Injector -> Css Injector and unselected Preprocess CSS

Did we miss something from #3169757 fix?

cilefen’s picture

#3169757: WSOD and Uncaught PHP Exception Exception: "Only file CSS assets can be optimized." would be the place to talk about that. All this is on the assumption that the "999" group is from that module. You could search your codebase for 999 in case it is elsewhere.

je1’s picture

StatusFileSize
new1.67 KB

Attached is the 999 that I can find in the code base, removed the strings other than just 999.

Not sure, is that what we looking for?

./modules/asset_injector/src/Form/AssetInjectorFormBase.php: '#weight' => 999,

cilefen’s picture

If this were my codebase I would consider this identified. I'm marking this as a duplicate.

je1’s picture

I searched only the *.php and *.inc files, should I search all files or that is enough?

je1’s picture

Uninstalling the module (Asset Injector) resolved this issue.