Problem/Motivation
Early error handling (attempts to display PHP warnings, notices, etc), results in a fatal error since the \Drupal::$container
is not yet instantiated.
How to reproduce
Add this line to settings.php
:
$config['my.override'] = $undefined_variable_typo;
Load a page, see a WSOD or a fatal error depending on error display settings.
Proposed resolution
Don't rely on the \Drupal::$container
for displaying errors early on.
Remaining tasks
Fix it.
User interface changes
Will display errors outside of drupal_set_message()
if they are thrown early enough.
API changes
No public API changes.
Original report by eule
Hi, i just try out the new d8 dev14+13 on a new environment. running
- ubuntu 14.04 trusty
- hhvm
- nginx1.6.0
- mariadb10.0
after i upload all and visit the root i become this error msg.
If you have just changed code (for example deployed a new module or moved an existing one) read http://drupal.org/documentation/rebuild
Additional uncaught exception thrown while handling exception.
Original
BadMethodCallException: Call to a member function get() on a non-object (NULL) in Drupal::logger() (line 647 of /var/www/xxx/core/lib/Drupal.php).
Drupal::logger('php')
_drupal_log_error(Array, )
_drupal_error_handler_real(2048, 'It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead', '/var/www/xxx/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Response.php', 206, Array)
_drupal_error_handler(2048, 'It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead', '/var/www/xxx/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Response.php', 206, Array)
DateTime->__construct('', Object)
Symfony\Component\HttpFoundation\Response->__construct('', 302, Array)
Symfony\Component\HttpFoundation\RedirectResponse->__construct('/core/install.php')
Drupal\Core\DrupalKernel::createFromRequest(Object, Object, 'prod')
Additional
BadMethodCallException: Call to a member function get() on a non-object (NULL) in Drupal::moduleHandler() (line 414 of /var/www/xxx/core/lib/Drupal.php).
Drupal::moduleHandler()
_drupal_maintenance_theme()
drupal_maintenance_theme()
_drupal_log_error(Array, 1)
_drupal_exception_handler(Object)
after this i go to ./core/install.php here works all fine to the point of the install. white site http://www.example.com/core/install.php?langcode=de&profile=standard tables are in db created but just 15
if i visit my root again i become now this error msg
Warning: array_keys() expects parameter 1 to be an array or collection in Drupal\Core\Authentication\AuthenticationManager->handleException() (line 185 of core/lib/Drupal/Core/Authentication/AuthenticationManager.php).
Warning: array_intersect() expects parameter 2 to be an array or collection in Drupal\Core\Authentication\AuthenticationManager->handleException() (line 185 of core/lib/Drupal/Core/Authentication/AuthenticationManager.php).
Warning: Invalid argument supplied for foreach() in Drupal\Core\Authentication\AuthenticationManager->handleException() (line 191 of core/lib/Drupal/Core/Authentication/AuthenticationManager.php).
Page not found
The requested page "/" could not be found.
hope it helps
Comment | File | Size | Author |
---|---|---|---|
#24 | error-handling-2317913-24.patch | 1.57 KB | jhedstrom |
#24 | interdiff.txt | 1.38 KB | jhedstrom |
Comments
Comment #1
eule CreditAttribution: eule commentedComment #2
eule CreditAttribution: eule commentedhi,
i put the Priority higher because i test in my environment Drupal7 & Wordpress. Both CMS and Bloggin Systems working in my environment. So this seems to me a Problem with the HHVM compatibility.
If you know more about it change the Priority back. Thanks
Comment #3
eule CreditAttribution: eule commentedHHVM error LOG
Comment #4
eule CreditAttribution: eule commentedComment #5
eule CreditAttribution: eule commentedComment #6
eule CreditAttribution: eule commentedComment #7
eule CreditAttribution: eule commentedComment #8
eule CreditAttribution: eule commentedComment #9
swentel CreditAttribution: swentel commentedHHVM compatibility is tracked in #2165377: [meta] HHVM compatibility - we should add this as a sub issue of it, but this is not critical atm.
Comment #10
eule CreditAttribution: eule commentedComment #11
dawehnerIs this still active?
Comment #12
eule CreditAttribution: eule commentednot sure yet. but i think so.
Comment #13
eule CreditAttribution: eule commentedNope this seems not to be fixed!
i setup a new site with latest D8 dev and updated the system to hhvm 3.3.0
drupal is not installed and i visit my page. this redirects me not to ./core/install but gives me a huge error message like i here postet - i go to ./core/install and install drupal ...this works! and drupal runs!
this i got in my hhvm log
\nFatal error: Uncaught exception 'BadMethodCallException' with message 'Call to a member function get() on a non-object (NULL)' in /var/www/example/core/lib/Drupal.php:138\nStack trace:\n#0 /var/www/example/core/includes/bootstrap.inc(910): Drupal::service()\n#1 /var/www/example/core/includes/errors.inc(221): drupal_set_message()\n#2 /var/www/example/core/includes/errors.inc(77): _drupal_log_error()\n#3 /var/www/example/core/includes/bootstrap.inc(1062): _drupal_error_handler_real()\n#4 (): _drupal_error_handler()\n#5 /var/www/example/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Response.php(206): DateTime->__construct()\n#6 /var/www/example/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/RedirectResponse.php(44): Symfony\\Component\\HttpFoundation\\Response->__construct()\n#7 /var/www/example/core/lib/Drupal/Core/DrupalKernel.php(215): Symfony\\Component\\HttpFoundation\\RedirectResponse->__construct()\n#8 /var/www/example/index.php(20): Drupal\\Core\\DrupalKernel::createFromRequest()\n#9 {main}
maybe again a hhvm issue?
Comment #14
jhedstromI don't think this is specific to hhvm, I think the error thrown is simply an uncaught exception instead of a fatal error.
This error can be reproduced by simply adding
$foo = $bar
insettings.php
. This tries to display a PHP notice, but results in a far worse fatal error since the container is not yet instantiated in\Drupal
:This surfaced in the Drush issue queue as well when we were missing an argument to a method. What should have been a PHP warning resulted in this same fatal error.
Comment #15
jhedstromComment #16
jhedstromThis resolves the issue, not in the most elegant way though. It also results in unthemed notices/warnings at the top of the page if the error is thrown too early.
I'm bumping to critical since this seems like a crucial DX issue.
Comment #17
jhedstromComment #18
znerol CreditAttribution: znerol commentedThis is the same issue as #2223575: PHP Fatal error: Call to a member function get() on a non-object which has other issues linked as well.
Comment #20
alexpottRather than getting the container here we should use
hasService('app.root')
Let's be honest here are check if we have the
page_cache_kill_switch
service instead.Comment #21
znerol CreditAttribution: znerol commentedOr
session_manager
, that might be a bit more obvious for people reading the code?Comment #22
alexpott@znerol yep that makes sense +1
Comment #23
catchI think this is a duplicate of an old issue, but I can't find that old issue at the moment.
What about calling set_error_handler() and set_exception_handler() at the end of, or just after DrupalKernel::initializeContainer() instead of DrupalKernel::bootEnvironment() - then the container dependency is met.
If there's an exception while building the container you get an unthemed error but that's an extremely unlucky production error to have.
Adding the explicit check for the session service inside the error handler is decent too though.
Comment #24
jhedstromI should have read further through
errors.inc
,\Drupal::hasService()
is what I was looking for.Comment #25
dcrocks CreditAttribution: dcrocks commentedIs what they are doing in #2363341: Throw exception in Drupal::service() and friends, if container not initialized yet. related?
Comment #26
jhedstromI posted #24 without seeing #23.
Comment #27
dawehnerThat itself is already an improvement, one less reason to fail during the error handling.
Comment #28
alexpottre #25 not really. We still need to avoid calling the session_manager if it does not exist yet. This patch would be no different if that had landed already.
I think we should explore moving the error handler setting in DrupalKernel::boot() in another patch. As @dawehner says this makes things better already. This issue addresses a critical bug and is allowed per https://www.drupal.org/core/beta-changes. Committed 99d219a and pushed to 8.0.x. Thanks!
Comment #30
znerol CreditAttribution: znerol commentedThere might be multiple duplicate issues about this, e.g. #2223575: PHP Fatal error: Call to a member function get() on a non-object. Those should be closed as duplicate.