On some (fatal?) errors, I get another fatal error when trying to display the first fatal error...

Catchable fatal error: Argument 1 passed to Drupal\Core\Theme\ThemeManager::setActiveTheme() must be an instance of Drupal\Core\Theme\ActiveTheme, null given, called in /[...]/core/includes/errors.inc on line 128 and defined in /[...]/core/lib/Drupal/Core/Theme/ThemeManager.php on line 119

Making the parameter optional fixes it.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

eshta’s picture

I experienced the same problem with the latest build and this resolved it so that I saw the standard error message again.

tanc’s picture

Confirming that this patch allowed the standard error message to show.

TR’s picture

Status: Needs review » Reviewed & tested by the community

I've been experiencing this error for more than a week while developing D8 code, and it's frustrating because whenever I make a mistake this error is thrown from error.inc, hiding the actual problem. As an example, I once added a field in my db_insert() which didn't exist in the table. Whoops, but the error was this "ActiveTheme" error which wasn't helpful at all. Since I had made many code additions, it took me a good while to figure out which one caused the error, and what the error realy was.

I tested the patch and yes, I can now see the original error, not the bogus "ActiveTheme" error. This will save me a LOT of time. Thanks.

Berdir’s picture

The obvious question of course is if we can test this and how. I really don't know why this doesn't show up in our existing tests.

webchick’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs tests

Indeed. Let's put our thinking caps on here. Does anyone here have more info on how you've triggered this in the past?

Berdir’s picture

Looks like we only have tests for exceptions but not php errors, which are, for some reason running through a different code path.

Exceptions are DefaultExceptionSubscriber, errors go through _drupal_log_error(), only the second one calls the theme stuff.

TR’s picture

Another way I triggered it is when porting a hook_theme() from D7 to D8. D7 defaults to 'function' while D8 defaults to 'template'. So those cases where I had used a theme function in D7 without a 'function' key ended up causing this error in D8, but of course only at the point where Drupal tried to load what it assumed was a template.

I don't think that what I describe here or above in #3 are PHP errors, although a PHP error may eventually result somewhere down the line. Here, it's just a missing template (I would think that's already tested for somewhere?). In #3, it boils down to an error in the SQL statement which is eventually constructed from my bad instructions.

dawehner’s picture

Issue tags: -Needs tests
FileSize
5.52 KB
6.68 KB

Let's write indeed a test for it.

Berdir’s picture

Priority: Normal » Major
Status: Needs review » Reviewed & tested by the community

Given that this happens for all errors and not just some rare special case, I think this is at least major.

Test looks good to me, RTBC if bot agrees.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 8: 2451085-8.patch, failed testing.

The last submitted patch, 8: 2451085-test.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
6.64 KB
1.3 KB

Things aren't that easy always.

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

Ok, now testbot is happy :)

Arla’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
5.47 KB

Let's check that this fails without the fix.

Status: Needs review » Needs work

The last submitted patch, 14: 2451085-12-tests_only.patch, failed testing.

Arla’s picture

Status: Needs work » Reviewed & tested by the community

Perfect. Back to RTBC.

dawehner’s picture

Status: Reviewed & tested by the community » Needs work

Testbot is not happy

dawehner’s picture

Status: Needs work » Reviewed & tested by the community

dawehner is stupid.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/system/src/Tests/System/ErrorHandlerTest.php
@@ -46,6 +46,11 @@ function testErrorHandler() {
+      '!message' => 'Argument 1 passed to Drupal\error_test\Controller\ErrorTestController::Drupal\error_test\Controller\{closure}() must be of the type array, string given, called in /Users/dawehner/www/d8/core/modules/system/tests/modules/error_test/src/Controller/ErrorTestController.php on line 66 and defined',

I don't understand how this works? How can we have files at /Users/dawehner/www/? Something feels wrong.

dawehner’s picture

Status: Needs work » Needs review
FileSize
6.76 KB
2.23 KB

Ha, that was fun :)

dawehner’s picture

FileSize
0 bytes

Here is a test only patch.

dawehner’s picture

FileSize
2.58 KB

This time, less empty.

Grimreaper’s picture

Hello,

Thanks you very much. I have applied the patch from comment 20 and it works perfectly.

Status: Needs review » Needs work

The last submitted patch, 22: test-only.patch, failed testing.

Arla’s picture

Status: Needs work » Needs review
FileSize
6.16 KB
1.72 KB
5.6 KB

Actually, why don't we use the existing resetActiveTheme() instead :)

Status: Needs review » Needs work

The last submitted patch, 25: 2451085-25-test-only.patch, failed testing.

Arla’s picture

Status: Needs work » Needs review

Test-only patch failed, so ready for review.

neclimdul’s picture

Status: Needs review » Reviewed & tested by the community

Works for me. Back to RTBC

Berdir’s picture

Nice, that looks better.

I guess a partial patch of the error message would have been OK too, because this will break if the line number changes, but that won't happen often (ever?), as it is inside a test controller that won't change much.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This issue addresses a major bug and is allowed per https://www.drupal.org/core/beta-changes. Committed 8b98854 and pushed to 8.0.x. Thanks!

  • alexpott committed 8b98854 on 8.0.x
    Issue #2451085 by dawehner, Arla: _drupal_log_error() passes NULL to...

Status: Fixed » Closed (fixed)

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