Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent "The specified database connection is not defined: [db_name]" when not installed #3733

Closed
nvaken opened this issue Jan 23, 2018 · 2 comments

Comments

@nvaken
Copy link
Contributor

nvaken commented Jan 23, 2018

Problem

[ERROR] The specified database connection is not defined: default

When you're running commands in a Drupal setup which is not installed it will always trigger this error. I think this error should not be triggered since all commands that are available are suited to be run against a uninstalled setup. This error makes it hard to use DC as a automation tool, since in this state you always receive an error.

Use case

For example, I've created a custom command that does some stuff on a non-installed Drupal setup, every time a colleague runs that command they are assuming something went wrong. That's not the case, it's just Drupal Core that's trying to bootstrap and cannot find a default database.

Suggestion

I'd suggest not showing this error. If there are commands that need to show feedback that they are unable to process or are only partly showing information etc... I think the warning should be more specific. Some practical examples to visualise what I mean:

drupal list

Replace database error and replace with a warning something like: No installed Drupal setup found, only showing commands that are available in uninstalled state.

drupal multisite:new

Now shows a [OK] message about successfully creating the multisite structure and directly after that shows the database ERROR, which makes no sense as output for this command. Remove the error.
image

drupal dotenv:init

First shows me a relevant information about files that have been created and then shows the database ERROR, which is irrelevant.

And more...

Those were just some examples, I think that this should be suffice the portrait what I'm saying. 😃

Resolution

  1. Make sure commands that are available in uninstalled state do not show database error.
  2. For the commands that need to show feedback (like drupal list) add more descriptive warnings.
@nvaken
Copy link
Contributor Author

nvaken commented Jan 23, 2018

I've just now started to debug this a little bit. I've noticed the error is being triggered in Drupal Core:

#0 d8-test.com-uninstalled/web/core/lib/Drupal/Core/Database/Database.php(166): Drupal\Core\Database\Database::openConnection('default', 'default')  <<<---- Triggering 
#1 [internal function]: Drupal\Core\Database\Database::getConnection('default')
#2 d8-test.com-uninstalled/vendor/symfony/dependency-injection/ContainerBuilder.php(885): call_user_func_array(Array, Array)
#3 d8-test.com-uninstalled/vendor/symfony/dependency-injection/ContainerBuilder.php(451): Symfony\Component\DependencyInjection\ContainerBuilder->createService(Object(Symfony\Component\DependencyInjection\Definition), 'database')
#4 d8-test.com-uninstalled/vendor/symfony/dependency-injection/ContainerBuilder.php(954): Symfony\Component\DependencyInjection\ContainerBuilder->get('database', 1)
#5 d8-test.com-uninstalled/vendor/symfony/dependency-injection/ContainerBuilder.php(951): Symfony\Component\DependencyInjection\ContainerBuilder->resolveServices(Object(Symfony\Component\DependencyInjection\Reference))
#6 d8-test.com-uninstalled/vendor/symfony/dependency-injection/ContainerBuilder.php(876): Symfony\Component\DependencyInjection\ContainerBuilder->resolveServices(Array)
#7 d8-test.com-uninstalled/vendor/symfony/dependency-injection/ContainerBuilder.php(451): Symfony\Component\DependencyInjection\ContainerBuilder->createService(Object(Symfony\Component\DependencyInjection\Definition), 'cache.backend.d...')
#8 d8-test.com-uninstalled/web/core/lib/Drupal/Core/Cache/ChainedFastBackendFactory.php(88): Symfony\Component\DependencyInjection\ContainerBuilder->get('cache.backend.d...')
#9 d8-test.com-uninstalled/web/core/lib/Drupal/Core/Cache/CacheFactory.php(83): Drupal\Core\Cache\ChainedFastBackendFactory->get('bootstrap')
#10 [internal function]: Drupal\Core\Cache\CacheFactory->get('bootstrap')
#11 d8-test.com-uninstalled/vendor/symfony/dependency-injection/ContainerBuilder.php(885): call_user_func_array(Array, Array)
#12 d8-test.com-uninstalled/vendor/symfony/dependency-injection/ContainerBuilder.php(451): Symfony\Component\DependencyInjection\ContainerBuilder->createService(Object(Symfony\Component\DependencyInjection\Definition), 'cache.bootstrap')
#13 d8-test.com-uninstalled/vendor/symfony/dependency-injection/ContainerBuilder.php(954): Symfony\Component\DependencyInjection\ContainerBuilder->get('cache.bootstrap', 1)
#14 d8-test.com-uninstalled/vendor/symfony/dependency-injection/ContainerBuilder.php(951): Symfony\Component\DependencyInjection\ContainerBuilder->resolveServices(Object(Symfony\Component\DependencyInjection\Reference))
#15 d8-test.com-uninstalled/vendor/symfony/dependency-injection/ContainerBuilder.php(876): Symfony\Component\DependencyInjection\ContainerBuilder->resolveServices(Array)
#16 d8-test.com-uninstalled/vendor/symfony/dependency-injection/ContainerBuilder.php(451): Symfony\Component\DependencyInjection\ContainerBuilder->createService(Object(Symfony\Component\DependencyInjection\Definition), 'module_handler')
#17 d8-test.com-uninstalled/web/core/lib/Drupal/Core/DrupalKernel.php(549): Symfony\Component\DependencyInjection\ContainerBuilder->get('module_handler')
#18 d8-test.com-uninstalled/vendor/drupal/console/src/Bootstrap/Drupal.php(172): Drupal\Core\DrupalKernel->preHandle(Object(Symfony\Component\HttpFoundation\Request)) <------ Entering Drupal Console
#19 d8-test.com-uninstalled/vendor/drupal/console/bin/drupal.php(79): Drupal\Console\Bootstrap\Drupal->boot()
#20 d8-test.com-uninstalled/vendor/drupal/console/bin/drupal(4): require('...')
#21 {main}

So, as you can see the callstack enters Drupal console in #18. As far as I can tell, at that point, commands are not available yet, as they are added in DrupalKernelTrait in addDrupalConsoleServices() and gets fire later then #18.

Is this even possible without a big rewrite?

@jmolivas
Copy link
Member

jmolivas commented Jan 30, 2018

Fixed with PR #3750

Now is possible to define which command shows the error messages?

I defaulted boot error messages to show only on list command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants