Wednesday, February 5, 2020

ArgumentCountError: Too few arguments to function Drush\Sql\SqlBase::__construct(), 1 passed

Ever encountered Drush error while running Drush commands in your local against sites hosted in Acquia? Here is a solution.

Drush command:
drush @example.dev status

Drush version:
Drush Commandline Tool 9.6.0

Drush error:
ArgumentCountError: Too few arguments to function Drush\Sql\SqlBase::__construct(), 1 passed and exactly 2 expected in Drush\Sql\SqlBase->__construct() (line 42 of /mnt/www/html/vendor/drush/drush/src/Sql/SqlBase.php).
ArgumentCountError: Too few arguments to function Drush\Sql\SqlBase::__construct(), 1 passed and exactly 2 expected in /mnt/www/html/vendor/drush/drush/src/Sql/SqlBase.php on line 42 #0 [internal function]: Drush\Sql\SqlBase->__construct(Array)
#1 /usr/local/drush8/vendor/drush/drush/includes/drush.inc(117): ReflectionClass->newInstanceArgs(Array)
#2 /usr/local/drush8/vendor/drush/drush/commands/sql/sql.drush.inc(532): drush_get_class('Drush\\Sql\\Sql', Array, Array)
#3 /usr/local/drush8/vendor/drush/drush/commands/sql/sql.drush.inc(549): drush_sql_get_class(Array)
#4 /usr/local/drush8/vendor/drush/drush/includes/environment.inc(389): drush_sql_get_class()
#5 /usr/local/drush8/vendor/drush/drush/lib/Drush/Boot/DrupalBoot.php(462): drush_valid_db_credentials()
#6 /usr/local/drush8/vendor/drush/drush/lib/Drush/Boot/DrupalBoot8.php(109): Drush\Boot\DrupalBoot->bootstrap_drupal_database_validate()
#7 /usr/local/drush8/vendor/drush/drush/includes/bootstrap.inc(430): Drush\Boot\DrupalBoot8->bootstrap_drupal_database_validate()
#8 /usr/local/drush8/vendor/drush/drush/includes/bootstrap.inc(507): drush_bootstrap_validate(4)
#9 /usr/local/drush8/vendor/drush/drush/includes/bootstrap.inc(456): drush_bootstrap_max()
#10 /usr/local/drush8/vendor/drush/drush/lib/Drush/Boot/BaseBoot.php(59): drush_bootstrap_to_phase(-2)
#11 /usr/local/drush8/vendor/drush/drush/includes/preflight.inc(67): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#12 /usr/local/drush8/vendor/drush/drush/drush.php(12): drush_main()
#13 {main}
Drush command terminated abnormally due to an unrecoverable error.       [error]

Fix:

  1. Go to your /sites containing *.site.yml files. In my case /home/sastha/sites
  2. vi example.site.yml
  3. Check "paths:" variable
  4. If other aliases are running fine, then set same for your problematic alias
  5. In my case, changed below from
       paths:
          drush-script: drush

         TO

        paths:
            drush-script: drush9

Wednesday, March 20, 2019

[success] No site aliases found. drush 9

[success] No site aliases found. drush 9

Running drush sa returns below message in drush 9?

[success] No site aliases found.

Here is the solution:
NOTE: Tested with drush installed globally

Run drush debug command:
drush st --debug -vvv
 Sample output from above:

 [preflight] Config paths: /home/sastha/.composer/vendor/drush/drush/drush.yml
 [preflight] Alias paths:
 [preflight] Commandfile search paths: /home/sastha/.composer/vendor/drush/drush/src
 [bootstrap] Starting bootstrap to max [0.3 sec, 7.64 MB]
 [debug] Trying to bootstrap as far as we can [0.3 sec, 7.64 MB]
 PHP binary    : /usr/bin/php7.2
 PHP config    : /etc/php/7.2/cli/php.ini
 PHP OS        : Linux
 Drush script  : /home/sastha/.composer/vendor/drush/drush/drush
 Drush version : 9.6.0
 Drush temp    : /tmp
 Drush configs : /home/sastha/.composer/vendor/drush/drush/drush.yml


Alias Path is missing as highlighted above


Sample drush.yml content:
sastha@DESKTOP $ cat /home/sastha/.composer/vendor/drush/drush/drush.yml
#This is a Drush config file. Sites may override this config to change minimum PHP.
drush:
  php:
    minimum-version: 5.6.0
  paths:
    alias-path:
     - /home/sastha/sites

Check if alias-path is set?

sastha@DESKTOP $ drush st --debug -vvv
 [preflight] Config paths: /home/sastha/.composer/vendor/drush/drush/drush.yml
 [preflight] Alias paths: /home/sastha/sites
 [preflight] Commandfile search paths: /home/sastha/.composer/vendor/drush/drush/src
 [bootstrap] Starting bootstrap to max [1.47 sec, 7.64 MB]
 [debug] Trying to bootstrap as far as we can [1.48 sec, 7.65 MB]
 PHP binary    : /usr/bin/php7.2
 PHP config    : /etc/php/7.2/cli/php.ini
 PHP OS        : Linux
 Drush script  : /home/sastha/.composer/vendor/drush/drush/drush
 Drush version : 9.6.0
 Drush temp    : /tmp
 Drush configs : /home/sastha/.composer/vendor/drush/drush/drush.yml

Problem solved!

Yes formatting is bad because no one is reading my blog except me :) :) :)

Friday, March 1, 2019

Drupal 8 Composer failure on Windows 7 with the message "bin\phpcs" "--config-show" "installed_paths"" failed.

Drupal 8 Composer failure with the below message on Windows 7:

 ""D:\www\mydrupalsite/vendor/bin\phpcs" "--config-show" "installed_paths"" failed.

Solution: 

Save this as phpcs.bat inside D:\www\vendor\bin:

@ECHO OFF
setlocal DISABLEDELAYEDEXPANSION
SET BIN_TARGET=%~dp0/../squizlabs/php_codesniffer/bin/phpcs
php "%BIN_TARGET%" %*

Monday, February 4, 2019

DrupalcampNJ: YouTube Channel

Drupal 8: Using Kint to print views fields

How to print fields variable of a views?

{{ kint(fields) }}

To resolve Out of memory issue:
https://www.drupal.org/project/devel/issues/2764023

Edit modules/devel/kint/kint/config.default.php and set $_kintSettings['maxLevels'] to a lower number (the default is 7)

My recommendation: Set it to 4 if you are using Windows


PHP error while enabling Drupal 8 Devel Module

Error Message:
The website encountered an unexpected error. Please try again later.Symfony\Component\Routing\Exception\RouteNotFoundException: Route "devel.execute_php" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 202 of core\lib\Drupal\Core\Routing\RouteProvider.php).

Reason:
Most probably you are installing Devel module (8.x-2.0) with Admin Toolbar installed

Fix:
https://www.drupal.org/project/admin_toolbar/issues/3009193
Upgrade to latest version of Admin Toolbar (8.x-1.26)

Monday, April 6, 2015

Acquia Certified Developer

I am a proud Acquia Certified Developer (Drupal) from today! :)