Problem/Motivation

When I attempt to scan a module with a node_modules that includes the normalize.css package the scan completes and reports 1 problem but it's just a stack trace and nothing was actually scan.

Here's the last few bits from the giant call stack:

Notice: file_get_contents(): Read of 8192 bytes failed with errno=21 Is a directory in /app/docroot/modules/contrib/upgrade_status/src/CSSDeprecationAnalyzer.php on line 29
    Call Stack:
       [...]
        2.3305 6890880 16. call_user_func_array:{/app/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:123}($callback = [0 => class Drupal\upgrade_status\Controller\ScanResultController { protected $entityTypeManager = NULL; protected $entityFormBuilder = NULL; protected $languageManager = NULL; protected $configFactory = NULL; protected $keyValue = NULL; protected $currentUser = NULL; protected $stateService = NULL; protected $moduleHandler = NULL; protected $formBuilder = NULL; protected $loggerFactory = NULL; protected $messenger = NULL; protected $redirectDestination = NULL; protected $stringTranslation = NULL; protected $resultFormatter = class Drupal\upgrade_status\ScanResultFormatter { ... }; protected $projectCollector = class Drupal\upgrade_status\ProjectCollector { ... }; protected $renderer = class Drupal\Core\Render\Renderer { ... } }, 1 => 'analyze'], $args = [0 => 'custom_theme']) /app/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:123
        2.3305 6890952 17. Drupal\upgrade_status\Controller\ScanResultController->analyze($project_machine_name = 'custom_theme') /app/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:123
        2.8117 9084784 18. Drupal\upgrade_status\DeprecationAnalyzer->analyze($extension = class Drupal\Core\Extension\Extension { protected $type = 'theme'; protected $pathname = 'themes/custom/custom_theme/custom_theme.info.yml'; protected $filename = 'custom_theme.theme'; protected $splFileInfo = NULL; protected $root = '/app/docroot'; public $subpath = 'themes/custom/custom_theme'; public $origin = ''; public $info = ['name' => 'Custom Theme', 'type' => 'theme', 'description' => 'custom_theme.org website theme.', 'base theme' => 'stable', 'core_version_requirement' => '^9 || ^10', 'libraries' => [...], 'ckeditor_stylesheets' => [...], 'regions' => [...], 'logo' => 'images/logo.svg', 'components' => [...], 'core_incompatible' => FALSE, 'lifecycle' => 'stable', 'mtime' => 1675372635, 'engine' => 'twig', 'features' => [...], 'screenshot' => 'themes/custom/custom_theme/screenshot.png', 'version' => NULL, 'php' => '7.3.0', 'libraries_extend' => [...], 'libraries_override' => [...], 'dependencies' => [...], 'regions_hidden' => [...], 'upgrade_status_type' => 'custom', 'upgrade_status_next_major_compatible' => TRUE, 'project' => 'custom_theme', 'upgrade_status_next' => 'scan']; public $owner = 'core/themes/engines/twig/twig.engine'; public $prefix = 'twig'; public $status = 1; public $required_by = []; public $requires = ['stable' => class Drupal\Core\Extension\Dependency { ... }]; public $sort = -3; public $base_themes = ['stable' => 'Stable']; public $module_dependencies = [] }, $options = ???) /app/docroot/modules/contrib/upgrade_status/src/Controller/ScanResultController.php:138
        80.7649 15888072 19. Drupal\upgrade_status\CSSDeprecationAnalyzer->analyze($extension = class Drupal\Core\Extension\Extension { protected $type = 'theme'; protected $pathname = 'themes/custom/custom_theme/custom_theme.info.yml'; protected $filename = 'custom_theme.theme'; protected $splFileInfo = NULL; protected $root = '/app/docroot'; public $subpath = 'themes/custom/custom_theme'; public $origin = ''; public $info = ['name' => 'Custom Theme', 'type' => 'theme', 'description' => 'custom_theme.org website theme.', 'base theme' => 'stable', 'core_version_requirement' => '^9 || ^10', 'libraries' => [...], 'ckeditor_stylesheets' => [...], 'regions' => [...], 'logo' => 'images/logo.svg', 'components' => [...], 'core_incompatible' => FALSE, 'lifecycle' => 'stable', 'mtime' => 1675372635, 'engine' => 'twig', 'features' => [...], 'screenshot' => 'themes/custom/custom_theme/screenshot.png', 'version' => NULL, 'php' => '7.3.0', 'libraries_extend' => [...], 'libraries_override' => [...], 'dependencies' => [...], 'regions_hidden' => [...], 'upgrade_status_type' => 'custom', 'upgrade_status_next_major_compatible' => TRUE, 'project' => 'custom_theme', 'upgrade_status_next' => 'scan']; public $owner = 'core/themes/engines/twig/twig.engine'; public $prefix = 'twig'; public $status = 1; public $required_by = []; public $requires = ['stable' => class Drupal\Core\Extension\Dependency { ... }]; public $sort = -3; public $base_themes = ['stable' => 'Stable']; public $module_dependencies = [] }) /app/docroot/modules/contrib/upgrade_status/src/DeprecationAnalyzer.php:419
        82.6766 16361552 20. file_get_contents($filename = '/app/docroot/themes/custom/custom_theme/node_modules/normalize.css') /app/docroot/modules/contrib/upgrade_status/src/CSSDeprecationAnalyzer.php:29 {"message":"Scanned custom_theme"}

I'm able to work around the issue by temporarily renaming the normalize.css directory to something without the .css suffix.

Steps to reproduce

  1. Run npm install normalize.css in a theme folder.
  2. Attempt to scan the theme.

Proposed resolution

Prevent the scanner from evaluating files in node_modules? #3162997: Exclude node_modules from scan is somewhat related but this appears to be a different (and, indeed, the files in node_modules do not get reported on when i work around the issue).

Remaining tasks

Determine how to prevent this issue and create a patch.

CommentFileSizeAuthor
#3 3338745.patch858 bytesgábor hojtsy
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

wells created an issue. See original summary.

wells’s picture

Issue summary: View changes
gábor hojtsy’s picture

Version: 8.x-3.x-dev » 4.x-dev
Status: Active » Needs review
StatusFileSize
new858 bytes

We indeed have a few exclusions in the neon file but that does not expand to the CSS Deprecation analyzer. We can port the directory specific checks explicitly there. Such as this one? Throwed in a !is_dir check for good. While that itself would be enough to directly fix this issue, this fix would avoid unnecessarily scanning files that are under node_modules or bower_components.

wells’s picture

Status: Needs review » Reviewed & tested by the community

Fix makes sense and the patch applies and resolves the issue. Marking RTBC. Thanks!

joelpittet’s picture

You could also use $ignore_directories = Settings::get('file_scan_ignore_directories', []); which uses has those listed (and any other similar directories or custom ones).

But this just the trick for a good chunk of these. Thanks I'll leave it RTBC

randallquesadaa’s picture

I had exactly the same problem described and the patch #3 worked great for me.

norman.lol’s picture

RTBC++

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Needs review

Slightly earlier the ".css in directory name considered a file" problem was resolved in #3324201: CSSDeprecationAnalyzer::getAllCSSFiles() returns directories with a name that ends in ".css", but the code would still traverse into the non-intended directories and find CSS files there, even though it should not. I adapted the patch based on the suggestion from @joelpittet, so the behaviour is more adaptive to site configuration. Please review the MR, I am hiding the patch.

gábor hojtsy’s picture

Title: Scan fails trying to access the normalize.css package in node_modules » CSS files are found in node_modules and other third party directories
gábor hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

Updating credits. Tests prove this works well.

  • Gábor Hojtsy committed cae748ae on 4.x
    Issue #3338745 by Gábor Hojtsy, wells, joelpittet, randallquesadaa,...
gábor hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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