Full Scan is failed just few minutes after it started with error message :- " is_dir() expects parameter 1 to be a valid path, boolean given in is_dir() " in recent logs

Comments

Rutuj created an issue. See original summary.

herczogzoltan’s picture

Hey @Rutuj !

Thanks for the report! We released a new alpha version which contains extra features and bug fixes as well: https://www.drupal.org/project/upgrade_status/releases/8.x-1.0-alpha2

That would be a great help if you could try it out and comment if it solved your issue!

In case the issue still occurs, can you please provide the full backtrace (if you see any) or a list of modules that you use?

tclark62’s picture

We have this error, too. I believe it's because our site wasn't installed with composer and therefore the vendor directory is in Drupal root directory. The backtrace is below.

TypeError: is_dir() expects parameter 1 to be a valid path, bool given in is_dir() (line 320 of [...]\vendor\mglaman\phpstan-drupal\src\Drupal\ExtensionDiscovery.php) 
#0 [...]\vendor\mglaman\phpstan-drupal\src\Drupal\ExtensionDiscovery.php(320): is_dir(false) 
#1 [...]\vendor\mglaman\phpstan-drupal\src\Drupal\ExtensionDiscovery.php(139): PHPStan\Drupal\ExtensionDiscovery->scanDirectory('') 
#2 [...]\vendor\mglaman\phpstan-drupal\src\DependencyInjection\DrupalExtension.php(83): PHPStan\Drupal\ExtensionDiscovery->scan('profile') 
#3 [...]\vendor\nette\di\src\DI\Compiler.php(215): PHPStan\DependencyInjection\DrupalExtension->loadConfiguration() 
#4 [...]\vendor\nette\di\src\DI\Compiler.php(175): Nette\DI\Compiler->processExtensions() 
#5 [...]\vendor\nette\bootstrap\src\Bootstrap\Configurator.php(306): Nette\DI\Compiler->compile() 
#6 [internal function]: Nette\Configurator->generateContainer(Object(Nette\DI\Compiler)) 
#7 [...]\vendor\nette\di\src\DI\ContainerLoader.php(125): call_user_func_array(Array, Array) 
#8 [...]\vendor\nette\di\src\DI\ContainerLoader.php(85): Nette\DI\ContainerLoader->generate('Container_cee77...', Array) 
#9 [...]\vendor\nette\di\src\DI\ContainerLoader.php(47): Nette\DI\ContainerLoader->loadFile('Container_cee77...', Array) 
#10 [...]\vendor\nette\bootstrap\src\Bootstrap\Configurator.php(267): Nette\DI\ContainerLoader->load(Array, Array) 
#11 [...]\vendor\nette\bootstrap\src\Bootstrap\Configurator.php(242): Nette\Configurator->loadContainer() 
#12 [...]\vendor\phpstan\phpstan\src\DependencyInjection\ContainerFactory.php(64): Nette\Configurator->createContainer() 
#13 [...]\vendor\phpstan\phpstan\src\Command\CommandHelper.php(144): PHPStan\DependencyInjection\ContainerFactory->create('D:/www/tmp/upgr...', Array, Array) 
#14 [...]\modules\contrib\upgrade_status\src\DeprecationAnalyser.php(207): PHPStan\Command\CommandHelper::begin(Object(Symfony\Component\Console\Input\StringInput), Object(Symfony\Component\Console\Output\BufferedOutput), Array, NULL, NULL, NULL, 'D:/www/tmp/upgr...', NULL) 
#15 [...]\modules\contrib\upgrade_status\src\DeprecationAnalyser.php(157): Drupal\upgrade_status\DeprecationAnalyser->checkDeprecationErrorMessages(Array) 
#16 [...]\modules\contrib\upgrade_status\src\Plugin\QueueWorker\UpgradeStatusDeprecationWorker.php(67): Drupal\upgrade_status\DeprecationAnalyser->analyse(Object(Drupal\Core\Extension\Extension)) 
#17 [...]\modules\contrib\upgrade_status\src\Controller\JobRunController.php(134): Drupal\upgrade_status\Plugin\QueueWorker\UpgradeStatusDeprecationWorker->processItem(Object(Drupal\Core\Extension\Extension)) 
#18 [internal function]: Drupal\upgrade_status\Controller\JobRunController->runNextJob() 
#19 [...]\core\lib\Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) 
#20 [...]\core\lib\Drupal\Core\Render\Renderer.php(582): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() 
#21 [...]\core\lib\Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) 
#22 [...]\core\lib\Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) 
#23 [...]\vendor\symfony\http-kernel\HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() 
#24 [...]\vendor\symfony\http-kernel\HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) 
#25 [...]\core\lib\Drupal\Core\StackMiddleware\Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#26 [...]\core\lib\Drupal\Core\StackMiddleware\KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#27 [...]\core\modules\page_cache\src\StackMiddleware\PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#28 [...]\core\modules\page_cache\src\StackMiddleware\PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#29 [...]\core\lib\Drupal\Core\StackMiddleware\ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#30 [...]\core\lib\Drupal\Core\StackMiddleware\NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#31 [...]\vendor\stack\builder\src\Stack\StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#32 [...]\core\lib\Drupal\Core\DrupalKernel.php(693): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#33 [...]\index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) 
#34 {main}.

I was able to get it to work for our site by changing line 55 of [...]\vendor\mglaman\phpstan-drupal\src\DependencyInjection\DrupalExtension.php accordingly:

- $finder->locateRoot(dirname($GLOBALS['autoloaderInWorkingDirectory'], 2));
+ $finder->locateRoot(dirname($GLOBALS['autoloaderInWorkingDirectory'], 1));

However, though this error no longer appears, and this solution worked for the alpha1 version, I get other, unrelated problems with alpha2 so that it doesn't scan any modules anymore.

gábor hojtsy’s picture

Title: error occurs as "full scan" is started » is_dir() expects parameter 1 to be a valid path, bool given

If you don't install this module with composer, several dependencies will not be downloaded. How did you get phpstan-drupal?

I think we can add requirements checks in this module to make sure the dependencies are at the place we expect them and don't let you enable it in Drupal if not so, but it would be important to understand how did you install it and what are the directory structures you have for core and this module's vendor libraries in particular.

gábor hojtsy’s picture

Title: is_dir() expects parameter 1 to be a valid path, bool given » Add requirements check to ensure dependencies are in place
Version: 8.x-1.0-alpha1 » 8.x-1.x-dev
Category: Bug report » Task

Refocusing as a task.

gábor hojtsy’s picture

Title: Add requirements check to ensure dependencies are in place » is_dir() expects parameter 1 to be a valid path, bool given
Category: Task » Bug report

Branch test on the project now result in the same problem, haha. So it probably is not just the dependency installation problem. Hm.

gábor hojtsy’s picture

Branch test with this fail at https://www.drupal.org/pift-ci-job/1316817

mglaman’s picture

The error is in PHPStan-Drupal

TypeError: is_dir() expects parameter 1 to be a valid path, bool given in is_dir() (line 320 of [...]\vendor\mglaman\phpstan-drupal\src\Drupal\ExtensionDiscovery.php) 
#0 [...]\vendor\mglaman\phpstan-drupal\src\Drupal\ExtensionDiscovery.php(320): is_dir(false) 
\vendor\mglaman\phpstan-drupal\src\Drupal\ExtensionDiscovery.php(139): PHPStan\Drupal\ExtensionDiscovery->scanDirectory('') 
#2 [...]\vendor\mglaman\phpstan-drupal\src\DependencyInjection\DrupalExtension.php(83): PHPStan\Drupal\ExtensionDiscovery->scan('profile') 

The code (which is a copy of Drupal core's)

    protected function scanDirectory($dir): array
    {
        $files = [];
        // In order to scan top-level directories, absolute directory paths have to
        // be used (which also improves performance, since any configured PHP
        // include_paths will not be consulted). Retain the relative originating
        // directory being scanned, so relative paths can be reconstructed below
        // (all paths are expected to be relative to $this->root).
        $dir_prefix = ($dir === '' ? '' : "$dir/");
        $absolute_dir = ($dir === '' ? $this->root : $this->root . "/$dir");
        if (!is_dir($absolute_dir)) {
            return $files;
        }

I'm guessing $this->root is somehow false?

    /**
     * Constructs a new ExtensionDiscovery object.
     *
     * @param string $root
     *   The app root.
     */
    public function __construct($root)
    {
        $this->root = $root;
gábor hojtsy’s picture

@mglaman: right, that does not mean that the problem is not caused by our module passing on invalid data :) I don't know honestly :)

mglaman’s picture

Yep, I don't think there are any guards here. $this->drupalRoot could be false.

        // Build the service definitions...
        $extensionDiscovery = new ExtensionDiscovery($this->drupalRoot);

Set by

        $finder = new DrupalFinder();
        if ($config['drupal_root'] !== '' && realpath($config['drupal_root']) !== false && is_dir($config['drupal_root'])) {
            $start_path = $config['drupal_root'];
        } else {
            $start_path = dirname($GLOBALS['autoloaderInWorkingDirectory'], 2);
        }
        $finder->locateRoot($start_path);
        $this->drupalRoot = $finder->getDrupalRoot();
        $this->drupalVendorDir = $finder->getVendorDir();
        if (! (bool) $this->drupalRoot || ! (bool) $this->drupalVendorDir) {
            throw new \RuntimeException("Unable to detect Drupal at $start_path");
        }

https://github.com/mglaman/phpstan-drupal/blob/master/src/DependencyInje...

kfritsche’s picture

For me the following fix worked: https://github.com/mglaman/phpstan-drupal/pull/75

After this I could run the tests locally for upgrade_status.

It fails but not tests fail?

PHPunit Test failed to complete; Error: PHPUnit 6.5.14 by Sebastian Bergmann and contributors.

Testing Drupal\Tests\upgrade_status\Functional\UpgradeStatusDeprecationDashboardAccessTest
.. 2 / 2 (100%)

Time: 52.28 seconds, Memory: 6.00MB

OK (2 tests, 11 assertions)

HTML output was generated
...

Remaining deprecation notices (2)

2x: The ""Symfony\Component\BrowserKit\Response::getStatus()"" method is deprecated since Symfony 4.3, use getStatusCode() instead.
1x in UpgradeStatusDeprecationDashboardAccessTest::testDeprecationDashboardAccessUnprivileged from Drupal\Tests\upgrade_status\Functional
1x in UpgradeStatusDeprecationDashboardAccessTest::testDeprecationDashboardAccessPrivileged from Drupal\Tests\upgrade_status\Functional

PHPunit Test failed to complete; Error: PHPUnit 6.5.14 by Sebastian Bergmann and contributors.

Testing Drupal\Tests\upgrade_status\Functional\UpgradeStatusAnalyseTest
. 1 / 1 (100%)

Time: 53 seconds, Memory: 6.00MB

OK (1 test, 26 assertions)

HTML output was generated
...

Remaining deprecation notices (2)

2x: file_prepare_directory() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\File\FileSystemInterface::prepareDirectory(). See https://www.drupal.org/node/3006851.
2x in UpgradeStatusAnalyseTest::testAnalyser from Drupal\Tests\upgrade_status\Functional

PHPunit Test failed to complete; Error: PHPUnit 6.5.14 by Sebastian Bergmann and contributors.

Testing Drupal\Tests\upgrade_status\Functional\UpgradeStatusUiTest
... 3 / 3 (100%)

Time: 1.89 minutes, Memory: 6.00MB

OK (3 tests, 54 assertions)

HTML output was generated
...

Remaining deprecation notices (2)

2x: file_prepare_directory() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\File\FileSystemInterface::prepareDirectory(). See https://www.drupal.org/node/3006851.
2x in UpgradeStatusUiTest::testUiAfterScan from Drupal\Tests\upgrade_status\Functional

volkswagenchick’s picture

Issue tags: +drupalnorth2019

Tagging for DrupalNorth 2019

gábor hojtsy’s picture

Status: Active » Postponed

This will be resolved by a followup to #3057853: Update to new PHPStan version for @deprecated support once another upstream fix is adde to the double Drupal class declaration. Currently half-broken in dev but @mglaman is working on it now. Nothing to do here.

gábor hojtsy’s picture

Status: Postponed » Postponed (maintainer needs more info)

https://www.drupal.org/project/upgrade_status/releases/8.x-1.0-alpha4 includes all the fixes and should work, please test!

gábor hojtsy’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Assuming this works, given no feedback in almost 4 weeks.