phpstan-drupal icon indicating copy to clipboard operation
phpstan-drupal copied to clipboard

Fatal error: Uncaught TypeError: is_link(): Argument #1 ($filename) must be of type string, Drush\Config\Environment given in /tmp/site/vendor/webflo/drupal-finder/src/DrupalFinder.php:153

Open DEVDESAGAR1 opened this issue 9 months ago • 6 comments

Bug report

Phpstan is failing due to code updated in the webflo : https://github.com/webflo/drupal-finder/pull/65/files Phpstan is using the this module error : Fatal error: Uncaught TypeError: is_link(): Argument #1 ($filename) must be of type string, Drush\Config\Environment given in /tmp/site/vendor/webflo/drupal-finder/src/DrupalFinder.php:153

Code snippet that reproduces the problem

DEVDESAGAR1 avatar May 09 '24 07:05 DEVDESAGAR1

Hello team,

I have created the pR for the fix : https://github.com/mglaman/phpstan-drupal/pull/757

DEVDESAGAR1 avatar May 09 '24 10:05 DEVDESAGAR1

Oh, it dropped as a minor release. Okay, thanks for reporting and the PR

mglaman avatar May 09 '24 22:05 mglaman

@DEVDESAGAR1 I'm curious what configuration you have? I'm not seeing it error this way, nor are the Drupal.org GitLab CI jobs

mglaman avatar May 10 '24 15:05 mglaman

I can't reproduce the failures, but for now I'm merging https://github.com/mglaman/phpstan-drupal/pull/758 to accept the deprecations

mglaman avatar May 10 '24 16:05 mglaman

I am facing this exact same issue where i just upgrading Drupal 10.1.14 to latest Drupal 10.2.6.

I can not run Drush updb and get the following error which is same as you guys are facing, whats the fix so far we have? Really blocked at this point on this error.

`PHP Fatal error: Uncaught TypeError: is_link(): Argument #1 ($filename) must be of type string, Drush\Config\Environment given in /var/www/html/vendor/webflo/drupal-finder/src/DrupalFinder.php:153 Stack trace: #0 /var/www/html/vendor/webflo/drupal-finder/src/DrupalFinder.php(153): is_link(Object(Drush\Config\Environment)) #1 /var/www/html/vendor/webflo/drupal-finder/src/DrupalFinder.php(75): DrupalFinder\DrupalFinder->discoverRoots(Object(Drush\Config\Environment)) #2 /var/www/html/vendor/drush/drush/src/Preflight/Preflight.php(310): DrupalFinder\DrupalFinder->__construct(Object(Drush\Config\Environment)) #3 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(58): Drush\Preflight\Preflight->preflight(Array) #4 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput)) #5 /var/www/html/vendor/drush/drush/drush.php(139): Drush\Runtime\Runtime->run(Array) #6 /var/www/html/vendor/drush/drush/drush(4): require('/var/www/html/v...') #7 /var/www/html/vendor/bin/drush(119): include('/var/www/html/v...') #8 {main} thrown in /var/www/html/vendor/webflo/drupal-finder/src/DrupalFinder.php on line 153

Fatal error: Uncaught TypeError: is_link(): Argument #1 ($filename) must be of type string, Drush\Config\Environment given in /var/www/html/vendor/webflo/drupal-finder/src/DrupalFinder.php:153 Stack trace: #0 /var/www/html/vendor/webflo/drupal-finder/src/DrupalFinder.php(153): is_link(Object(Drush\Config\Environment)) #1 /var/www/html/vendor/webflo/drupal-finder/src/DrupalFinder.php(75): DrupalFinder\DrupalFinder->discoverRoots(Object(Drush\Config\Environment)) #2 /var/www/html/vendor/drush/drush/src/Preflight/Preflight.php(310): DrupalFinder\DrupalFinder->__construct(Object(Drush\Config\Environment)) #3 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(58): Drush\Preflight\Preflight->preflight(Array) #4 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput)) #5 /var/www/html/vendor/drush/drush/drush.php(139): Drush\Runtime\Runtime->run(Array) #6 /var/www/html/vendor/drush/drush/drush(4): require('/var/www/html/v...') #7 /var/www/html/vendor/bin/drush(119): include('/var/www/html/v...') #8 {main} thrown in /var/www/html/vendor/webflo/drupal-finder/src/DrupalFinder.php on line 153 Failed to run drush updb -y: exit status 255`

Screenshot 2024-05-13 at 10 11 56 AM

ahsanra avatar May 13 '24 00:05 ahsanra

This was Drush issue and i have solved it by creating a patch for Drush 12.

I was running into this issue when I upgraded to Drush 11.x to 12.x on a Drupal 10.1.x and 10.2.x

Found the issue fix on drush github create a patch and apply it to 12.x version from here: https://github.com/drush-ops/drush/pull/5755/files

Note: This issue is fixed and merged in Drush 13.x as per pull request conversation https://github.com/drush-ops/drush/pull/5755

ahsanra avatar May 13 '24 04:05 ahsanra

I am not sure what i updated that is now causing this error:

Fatal error: Uncaught TypeError: is_link(): Argument #1 ($filename) must be of type string, Drush\Config\Environment given in E:\www\mysite\vendor\webflo\drupal-finder\src\DrupalFinder.php:153

but drush 12.5 and this patch: https://patch-diff.githubusercontent.com/raw/drush-ops/drush/pull/5755.patch does not fix it.

liquidcms avatar May 15 '24 19:05 liquidcms

Ah, i had 12.5.0 (and the patch); but require drush 12.5.2 (maybe 12.5.1 would work) and the patch to fix.

liquidcms avatar May 15 '24 20:05 liquidcms

I have drush 12.5.2 and the patch works.

Try to update drush to the version and let me know.

ahsanra avatar May 15 '24 23:05 ahsanra

Drush 12.5.1 + patch does not work. Drush 12.5.2 + patch does work, thanks!

matthiasm11 avatar May 16 '24 08:05 matthiasm11

So, is this not an issue with phpstan-drupal? I'm guessing not, since the CI is passing for build integrations

mglaman avatar May 16 '24 12:05 mglaman

@mglaman True, but there is a retro effect somewhere so you will have to tie it up with drush 12.5.1+

ahsanra avatar May 17 '24 00:05 ahsanra

Understood, but it's not caused by this package. Just both share this same dependency

mglaman avatar May 17 '24 23:05 mglaman

I had the same problem with Drush 12.4.3, it works 12.5.2 even without the patch.

Peppe87 avatar May 21 '24 16:05 Peppe87

I am using drush 12.5.2 When I use proposed patch : https://github.com/mglaman/phpstan-drupal/pull/757

I got this error:

RuntimeException thrown in /home/lob/www/fut/vendor/mglaman/phpstan-drupal/src/Drupal/DrupalAutoloader.php on line 109 while loading bootstrap file /home/lob/www/fut/vendor/mglaman/phpstan-drupal/drupal-autoloader.php: Unable to detect Drupal in /home/lob/www/fut/web

LOBsTerr avatar May 29 '24 07:05 LOBsTerr

I missed the part related to drush patch. So, to fix all issues, you need this patch: https://github.com/drush-ops/drush/pull/5755/files

LOBsTerr avatar May 29 '24 07:05 LOBsTerr

Updating to Drush 12.5.2 fixed this issue for me.

kevinquillen avatar May 29 '24 14:05 kevinquillen

Updating to 12.5.2 fixed the issue. No patch needed.

rf033 avatar May 29 '24 18:05 rf033

I just updated my sites, and am being bitten by this problem.

Updating to 12.5.2 does not fix the issue for me. I tried patching Drupal with https://github.com/drush-ops/drush/pull/5755/files, to no avail.

FWIW, I don't understand why this is triggering, as my document root is not a symlink. My files directory (web/sites/default/files) is a symlink, though.

gwolf avatar Jun 04 '24 20:06 gwolf

Faced same issue on upgrading from Drupal 10.2.4 to 10.3.0

Updating Drush to 12.5.2 fixed the issue for me. No patch needed. Thanks!

Manish-Sharma1995 avatar Jun 25 '24 13:06 Manish-Sharma1995

Thank you @rf033 - your comment:https://github.com/mglaman/phpstan-drupal/issues/756#issuecomment-2138023157 worked in my case.

2 ways to update drush:

  1. On my local personal dev environment set up, using ddev, I updated drush by doing:
ddev composer require drush/drush
robdaviswork@192 ligc-staging % ddev composer require drush/drush
./composer.json has been updated
Running composer update drush/drush
Loading composer repositories with package information
Updating dependencies
Lock file operations: 0 installs, 1 update, 0 removals
  - Upgrading drush/drush (12.5.1 => 12.5.2)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
  - Downloading drush/drush (12.5.2)
  - Upgrading drush/drush (12.5.1 => 12.5.2): Extracting archive
Generating autoload files
51 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found.
Using version ^12.5 for drush/drush

I now no longer get errors if doing ddev drush cr or ddev drush updb

  1. on my server / and generally for the codebase I would do:
composer require drush/drush

therobyouknow avatar Jun 26 '24 19:06 therobyouknow

Updating Drush to 12.5.2 fixed the issue for me. No patch needed.

blitke avatar Jul 08 '24 16:07 blitke