Getting following exceptions on a fresh drupal 8 installation while running drush command. I am using Drush Version : 7.0-dev

Additional uncaught exception thrown while handling exception.

Original

Drupal\Core\DependencyInjection\ContainerNotInitializedException: \Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container. in Drupal::getContainer() (line 129 of /Library/WebServer/Documents/drupal-8/core/lib/Drupal.php).

Drupal::getContainer()
drupal8_bootstrap(0)
_drush_bootstrap_drupal_configuration()
drush_bootstrap(3, 5)
drush_bootstrap_to_phase(5)
Drush\Boot\DrupalBoot->bootstrap_and_dispatch()
drush_main()

Additional

Drupal\Core\DependencyInjection\ContainerNotInitializedException: \Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container. in Drupal::getContainer() (line 129 of /Library/WebServer/Documents/drupal-8/core/lib/Drupal.php).

Drupal::getContainer()
Drupal::theme()
_drupal_log_error(Array, 1)
_drupal_exception_handler(Object)

Drush command terminated abnormally due to an unrecoverable error. [error]

Comments

berdir’s picture

Category: Bug report » Support request
Status: Active » Fixed
Issue tags: -#uncaught #exception #drupal #command

You need to update drush to the latest dev-master (or possibly an alpha, I don't know).

adhariwal’s picture

@Berdir, It did not help. I updated my drush to the latest dev-master and run the command again but receiving this error again.

adhariwal’s picture

Status: Fixed » Active
adhariwal’s picture

my drush version:

Drush Version : 7.0.0-alpha9 and running drush cc all command returns this error:

exception [error]
'Drupal\Core\DependencyInjection\ContainerNotInitializedException'
with message '\Drupal::$container is not initialized yet.
\Drupal::setContainer() must be called with a real container.' in
/Library/WebServer/Documents/drupal-8/core/lib/Drupal.php:129
Stack trace:
#0 /Library/WebServer/Documents/drupal-8/core/lib/Drupal.php(454):
Drupal::getContainer()
#1 /usr/local/bin/drush/commands/core/views.d8.drush.inc(458):
Drupal::moduleHandler()
#2 [internal function]: views_drush_cache_clear(Array)
#3 /usr/local/bin/drush/includes/command.inc(1294):
call_user_func_array('views_drush_cac...', Array)
#4 /usr/local/bin/drush/commands/core/cache.drush.inc(238):
drush_command_invoke_all_ref('drush_cache_cle...', Array)
#5 /usr/local/bin/drush/commands/core/cache.drush.inc(100):
drush_cache_clear_types(false)
#6 [internal function]: drush_cache_clear_pre_validate('all')
#7 /usr/local/bin/drush/includes/command.inc(359):
call_user_func_array('drush_cache_cle...', Array)
#8 /usr/local/bin/drush/includes/command.inc(210):
_drush_invoke_hooks(Array, Array)
#9 [internal function]: drush_command('all')
#10 /usr/local/bin/drush/includes/command.inc(178):
call_user_func_array('drush_command', Array)
#11 /usr/local/bin/drush/lib/Drush/Boot/DrupalBoot.php(68):
drush_dispatch(Array)
#12 /usr/local/bin/drush/drush.php(71):
Drush\Boot\DrupalBoot->bootstrap_and_dispatch()
#13 /usr/local/bin/drush/drush.php(11): drush_main()
#14 {main}

adhariwal’s picture

Category: Support request » Bug report
joshi.rohit100’s picture

I am facing same issue ):

berdir’s picture

Category: Bug report » Support request
Status: Active » Fixed

Are you sure that you didn't see https://github.com/drush-ops/drush/pull/1230, which was broken yesterday?

@adhariwal: I have no idea why that command is even doing something for you, drush cc all in D8 doesn't work, use drush cr.

drush cc all gives me just this:
$ drush cc all
`cache-clear all` is deprecated for Drupal 8 and later. Please use the `cache-rebuild` command instead.

Status: Fixed » Closed (fixed)

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

kanzer’s picture

The same problem a new drupal-8-beta-9 site.

Drush version : 7.0-dev

I upgrade drush today:
composer global update

I get an error:

Drupal\Core\DependencyInjection\ContainerNotInitializedException: \Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container. in Drupal::getContainer() (line 129 of /var/www/mysite/core/lib/Drupal.php).
Drush command terminated abnormally due to an unrecoverable error. 

with sites drupal 7 everything works fine

mgifford’s picture

I updated drush against the git repository when I ran into this error. It's working fine for me now in D8.

picacsso’s picture

Still not working for me. Only command that works is drush cr. When i attempt drush cc all I get the same error as reported by previous users.

Here's my setup:

Drush was attempting to connect to:
Drupal version : 8.0.0-beta10
Site URI : http://default
Database driver : mysql
Database hostname : localhost
Database port : 3306
Database username : root
Database name : drupal8
PHP configuration : /Applications/MAMP/bin/php/php5.4.26/conf/php.ini
PHP OS : Darwin
Drush script : /Users/macbook/drush/drush.php
Drush version : 7.0-dev
Drush temp : /tmp
directory
Drush configuration :
Drush alias files :
Drupal root : /Users/macbook/Sites/drupal8/drupal
Site path : sites/default
Active config path : sites/default/files/config_3_ymvnHNz0lDihkBUuaFWa5dPPiqax910aXDJBpwIC_VEgRfniAs91z5Y_aaKvU6je
X2vDFLOQ/active
Staging config path : sites/default/files/config_3_ymvnHNz0lDihkBUuaFWa5dPPiqax910aXDJBpwIC_VEgRfniAs91z5Y_aaKvU6je
X2vDFLOQ/staging

Attempted to enable a custom module (tried this from different directories withing D8 and still nada):

drush en my_module
Command pm-enable needs a higher bootstrap level to run - you will need to invoke drush from a more functional Drupal    [error]
environment to run this command.
The drush command 'en emko' could not be executed.                                                                       [error]
Drush was not able to start (bootstrap) the Drupal database.                                                             [error]
Hint: This may occur when Drush is trying to:
 * bootstrap a site that has not been installed or does not have a configured database. In this case you can select
another site with a working database setup by specifying the URI to use with the --uri parameter on the command line. See
`drush topic docs-aliases` for details.
 * connect the database through a socket. The socket file may be wrong or the php-cli may have no access to it in a
jailed shell. See http://drupal.org/node/1428638 for details.               
artofeclipse’s picture

Hi, I was facing the same issue as @emko_one, but and I got it fixed by doing some updates to my composer installation and make sure that I have mysql.sock in /tmp/ folder.

the new version of MAMP store the tmp files by default in his own folder, so make sure to add a symlink to your tmp.

I hope help some.

Thanks.

nikky171091’s picture

I am facing same issue ):

nikky171091’s picture

Got the solution

drush cr all

helonaut’s picture

@artofeclipse Thanks man, when I got a new laptop I installed the new version of MAMP and had the same problem. Going into /tmp and creating a symlink to the MAMP socket file was the solution:

cd /tmp
ln -s /Applications/MAMP/tmp/mysql/mysql.sock mysql.sock
jmagunia’s picture

I was also getting this error:

exception 'Drupal\Core\DependencyInjection\ContainerNotInitializedException' with message '\Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container.' in [error] /OBSCURED/core/lib/Drupal.php:129

SQLite users should check to make sure their DB is writable by the user who is executing drush.

aangel’s picture

This person cleared the problem by changing file permissions.

sjerdo’s picture

Nvm. Seems like I commented on the wrong issue.

I experience this error when executing drush php-eval.

ressa’s picture

I was getting the error below, and found this issue:

[preflight] Drush::$container is not initialized yet. \Drupal::setContainer() must be called with a real container.

Setting /tmp write permissions to 777 fixed it.