I was creating a form with an element that uses #ajax.
There are two ways core currently specifies callbacks (in this place, the method is called "statesAjax"):
1) 'callback' => '::statesAjax',
2) 'callback' => array(get_class($this), 'statesAjax'),

I accidentally mixed them up and specified array('::statesAjax') as the callback.
This gave me the completely unhelpful message:

Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\HttpException: "Internal Server Error" at core/modules/system/src/Controller/FormAjaxController.php line 102

Going to the class & line in question showed me the issue, but it would be better DX if the exception told me the exact cause right away.

Patch to follow...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bojanz’s picture

Status: Active » Needs review
FileSize
774 bytes

It's possible that a test might need to be modified. Let's see what fails.

dawehner’s picture

+++ b/core/modules/system/src/Controller/FormAjaxController.php
@@ -99,7 +99,7 @@ public function content(Request $request) {
-      throw new HttpException(500, t('Internal Server Error'));
+      throw new HttpException(500, t('The specified #ajax callback is empty or not callable.'));

Is there any reason on earth we have to translate this message?

bojanz’s picture

Yeah, good point, most parts of core don't translate the exceptions. I'll remove that.

bojanz’s picture

It actually passed. Here's a patch without the t().

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

+1

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 4: 2399221-4-fix-callback-exception.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: 2399221-4-fix-callback-exception.patch, failed testing.

Status: Needs work » Needs review
bojanz’s picture

Status: Needs review » Reviewed & tested by the community

Green again.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Strings are not frozen in the beta. Committed f4a817a and pushed to 8.0.x. Thanks!

  • alexpott committed f4a817a on 8.0.x
    Issue #2399221 by bojanz: Throw a friendly error when the #ajax callback...

Status: Fixed » Closed (fixed)

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