Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The exception response has been turned into text/plain last year for the purpose of security (SA-CORE-2016-004). For this reason HTML entities are now shown unprocessed. I propose we strip out HTML tags and decode special chars to make the error messages more readable.
Before:
The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">LogicException</em>: The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller? in <em class="placeholder">Symfony\Component\HttpKernel\HttpKernel->handleRaw()</em> (line <em class="placeholder">171</em> of <em class="placeholder">vendor/symfony/http-kernel/HttpKernel.php</em>). <pre class="backtrace">Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 656)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
</pre>
After:
The website encountered an unexpected error. Please try again later.
LogicException: The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller? in Symfony\Component\HttpKernel\HttpKernel->handleRaw() (line 171 of vendor/symfony/http-kernel/HttpKernel.php).
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 656)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Comment | File | Size | Author |
---|---|---|---|
#47 | 2872571-47.patch | 7.75 KB | ravi.shankar |
#38 | interdiff-2872571-36-38.txt | 618 bytes | yogeshmpawar |
#38 | 2872571-38.patch | 7.79 KB | yogeshmpawar |
#36 | interdiff-2872571-34-36.txt | 1.12 KB | yogeshmpawar |
#36 | 2872571-36.patch | 7.5 KB | yogeshmpawar |
Comments
Comment #2
Chi CreditAttribution: Chi commentedThe fix is pretty simple.
Comment #4
Chi CreditAttribution: Chi commentedThe change also simplifies a bit testing HTTP exceptions.
Comment #5
Chi CreditAttribution: Chi commentedComment #7
Chi CreditAttribution: Chi commentedReroll.
Comment #8
dawehnerIt is interesting that
\Drupal\Component\Render\PlainTextOutput::renderFromHtml
does something similar, but not the same.Comment #9
Chi CreditAttribution: Chi commentedWell maybe we should use it then.
Comment #10
Chi CreditAttribution: Chi commentedThere is no point to format backtrace with HTML.
Comment #11
Chi CreditAttribution: Chi commentedComment #14
dawehnerThis is all some legacy code inherited from the days when we tried to render exceptions in a drupal themed way.
Comment #15
Chi CreditAttribution: Chi commentedPlainTextOutput in some cases may return HTML which is not need when rendering exception.
This patch discards changes made in #9.
Comment #17
Chi CreditAttribution: Chi commentedComment #19
Chi CreditAttribution: Chi commentedRerolled the patch to 8.5.x.
Comment #23
Chi CreditAttribution: Chi commentedRerolled the patch to 8.7.x.
Comment #24
joachim CreditAttribution: joachim as a volunteer commentedComment #25
alexpottI'm wondering about removing the class and pre tags. Does this impact devel? I.e do we need a change record?
I think we should use
\Drupal\Component\Render\PlainTextOutput::renderFromHtml()
here - so we standardise on how we convert HTML to plain text.So are we fixing this on the right level - if you're seeing this in Drush or Console I think they should problem fix this.
Comment #26
Chi CreditAttribution: Chi commented@alexpott, because it is not an exception but TypeError. I suppose FinalExpceptionSubscriber does not handle such kind of errors.
I don't know how this is related to Devel module. Could you please explain possible implications?
Comment #27
Chi CreditAttribution: Chi commentedRerolled the patch to 8.7.x.
Comment #29
Chi CreditAttribution: Chi commentedComment #30
jhedstromComment #32
Chi CreditAttribution: Chi commentedComment #33
yogeshmpawarComment #34
yogeshmpawarRe-rolled the patch #27.
Comment #35
alexpottSince #2924860: “Uncaught exception” page contains HTML but has content-type text/plain landed this is now making the the output less not more developer friendly. I think we we should consider doing something like:
That way html output gets all the advantage of html and properly escaped errors and plain output looks good but has all HTML tags removed for the error message as we cannot be sure about the context it might be displayed it.
Comment #36
yogeshmpawarComments addressed in #35 & added an interdiff.
Comment #38
yogeshmpawarMissed to include
use Drupal\Component\Render\PlainTextOutput;
in patch. Updated patch added with an interdiff.Comment #40
jjwfcd CreditAttribution: jjwfcd commentedis this issue make the taxonomy term view page down related
?
The website encountered an unexpected error. Please try again later.LogicException: The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller? in Symfony\Component\HttpKernel\HttpKernel->handleRaw() (line 169 of /webroot/vendor/symfony/http-kernel/HttpKernel.php).
2019/07/07 05:05:46 [error] 30704#30704: *1582 FastCGI sent in stderr: "PHP message: Uncaught PHP Exception LogicException: "The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller?" at /webroot/vendor/symfony/http-kernel/HttpKernel.php line 169" while reading response header from upstream, client: 111.222.122.122, server: abc.doamin, request: "GET /taxonomy/term/10318 HTTP/2.0", upstream: "fastcgi://127.0.0.1:9999", host: "abc.domain"
with drupal core 8.7.4 and distribution varbase
https://www.drupal.org/project/varbase/issues/3066163
Comment #41
jjwfcd CreditAttribution: jjwfcd commentedComment #44
APolitsin CreditAttribution: APolitsin commentedнегодуэ
Subscribe
Comment #45
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedComment #46
Chi CreditAttribution: Chi commentedComment #47
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedHere I have tried to add reroll of patch #38 for Drupal 9.1.x.
Comment #48
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commented