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.
Problem/Motivation
Sometime i get error / exception backtraces that lack newlines in the dblog html view.
Without patch:
Error: Cannot use object of type Drupal\Core\Render\Markup as array in Drupal\leaflet\LeafletService->leafletProcessGeofield() (line 141 of /var/www/html/web/modules/contrib/leaflet/src/LeafletService.php) #0 /var/www/html/web/modules/contrib/leaflet/leaflet_views/src/Plugin/views/style/LeafletMap.php(441): Drupal\leaflet\LeafletService->leafletProcessGeofield(Array) #1 /var/www/html/web/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php(2112): Drupal\leaflet_views\Plugin\views\style\LeafletMap->render(Array) #2 /var/www/html/web/core/modules/views/src/ViewExecutable.php(1530): Drupal\views\Plugin\views\display\DisplayPluginBase->render() #3 /var/www/html/web/core/modules/views/src/Plugin/views/display/Page.php(171): Drupal\views\ViewExecutable->render() #4 /var/www/html/web/core/modules/views/src/ViewExecutable.php(1627): Drupal\views\Plugin\views\display\Page->execute() #5 /var/www/html/web/core/modules/views/src/Element/View.php(77): Drupal\views\ViewExecutable->executeDisplay('page_1', Array) #6 [internal function]: Drupal\views\Element\View::preRenderViewElement(Array) #7
With patch:
Error: Cannot use object of type Drupal\Core\Render\Markup as array in Drupal\leaflet\LeafletService->leafletProcessGeofield() (line 141 of /var/www/html/web/modules/contrib/leaflet/src/LeafletService.php). #0 /var/www/html/web/modules/contrib/leaflet/leaflet_views/src/Plugin/views/style/LeafletMap.php(441): Drupal\leaflet\LeafletService->leafletProcessGeofield(Array) #1 /var/www/html/web/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php(2112): Drupal\leaflet_views\Plugin\views\style\LeafletMap->render(Array) #2 /var/www/html/web/core/modules/views/src/ViewExecutable.php(1530): Drupal\views\Plugin\views\display\DisplayPluginBase->render() #3 /var/www/html/web/core/modules/views/src/Plugin/views/display/Page.php(171): Drupal\views\ViewExecutable->render() #4 /var/www/html/web/core/modules/views/src/ViewExecutable.php(1627): Drupal\views\Plugin\views\display\Page->execute() #5 /var/www/html/web/core/modules/views/src/Element/View.php(77): Drupal\views\ViewExecutable->executeDisplay('page_1', Array) #6 [internal function]: Drupal\views\Element\View::preRenderViewElement(Array) #7 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(378): call_user_func(Array, Array)
Proposed resolution
Add a
tag to *all* backtraces (one source line already has).Remaining tasks
Doit.User interface changes
n/aAPI changes
n/aData model changes
n/a
Comment | File | Size | Author |
---|---|---|---|
#60 | Screenshot-2019-12-16-09-40-22.png | 81.07 KB | dagmar |
#56 | 2930283-56.patch | 2.81 KB | Krzysztof Domański |
#56 | interdiff-50-56.txt | 1.22 KB | Krzysztof Domański |
#50 | 2930283-50.patch | 2.66 KB | Krzysztof Domański |
Comments
Comment #2
geek-merlinChanged all logs to use the same string, and all logger messages to use pre tag like already in verbose message codr branch.
(Interesting: The omissions are all on verrrry long code lines...)
Patch flying in that fixes this.
Comment #4
geek-merlinhmm ci dispatcher does 504, try later...
Comment #5
geek-merlinVisualize errorlog diff:
Fixed from:
to
Comment #6
geek-merlinComment #7
geek-merlin8.4 backport for those who like it.
Comment #11
geek-merlin(mispost)
Comment #13
geek-merlinComment #14
geek-merlinComment #15
dawehnerThank you for working on those improvements! They make a difference for some people :)
It is a bit weird to log HTML to be honest. Can't we make it a bit more obvious by introducing new lines here too?
Comment #16
geek-merlin> It is a bit weird to log HTML to be honest.
Yup. I thought that too but had no better idea.
> Can't we make it a bit more obvious by introducing new lines here too?
Can you elaborate (e.g. with a better patch ;-)?
\n? br-tag? Before the pre-tag? Remember that the pre tag is a block level tag.
Comment #17
hi_ten_ja CreditAttribution: hi_ten_ja commentedComment #19
geek-merlin#17: What's this? Looks like completely unrelated changes to me.
Comment #21
geek-merlinPatch flying in with a current 8.7 rebased version of #7 stripped down to a trivial oneliner.
I'm narrowing the scope to fix the annoying display of backtraces in dblog, so each line of the backtrace has one line, by simply adding a pre-tag around it. Fixing syslog can go to followups. Note that we already have HTML in that string, as the "%type" variable will be wrapped in em-tag, so no chance to bikeshed on that.
Let's get that in!
Comment #22
anruetherLooks good!
Comment #23
dagmarQuestion, can we add this when displaying the log instead when saving it? I see a potential break in log parsers (other than provided by core) that expect to see
%type: @message in %function (line %line of %file) @backtrace_string.
and now they also find html inside.I just tried this inside DbLogController::formatMessage() and seems to do the same thing. Also works for all error messages, not the new ones.
Comment #24
geek-merlin@dagmar #23:
It sounds very strange to me that people parse the HTML from the log, when they can swap out the error handler. (Do you do?)
They should know that HTML messages are not an API.
That said, if there's evidence that people do that i'd be all for a change note. Let's see what maintainer decides.
Comment #25
dagmar@axel.rutz thanks for your comment.
I'm not saying they will parse html looking for logs. By changing that line you are basically affecting all loggers because they will now get a new error message with a new structure. We should try to minimize this type of changes if we can avoid them. For example people grepping syslog messages will not be able to do this anymore unless they notice this change.
I cannot talk as core maintainer, but as current maintainer of the dblog and syslog modules I think it should be dblog responsibility to display the message properly. Even more when I shown in #23 is possible to do that without changing the log message structure.
If the main problem is that the dblog module is showing awful formatted back-traces, this seems more a visual fix than something to change when creating a log.
Comment #26
geek-merlinOK thanks i did not realize this, so i'm taking this a maintainer verdict.
Patch flying in that implements #23. Maybe we get this finally in for 8.7.
Escalating to major as this bug makes the backtrace hard to read.
Comment #27
dagmarThanks!. I would like to see a test that ensures this is working as expected.
Drupal\Tests\system\Functional\System\ErrorHandlerTest::testErrorHandler has some boilerplate you can use to trigger the exception and the code from Drupal\Tests\dblog\Functional\DbLogTest::testTemporaryUser() can be adapted to check the existence of the new
<pre></pre>
tags.Comment #29
Krzysztof Domański1. I added tests.
2. After adding the
<pre></pre>
tags, the dot displayed on a separate line at the end of the message. I moved the dot before backtrace.Comment #31
dagmarThis looks really good! Thanks @Krzysztof Domański
I think the mention to _drupal_log_error should be removed here. Since this function may chance anytime (it is internal).
In my opinion it would be better to just say. "Ensure backtrace strings are properly formatted", or something similar.
I tested the functionality as is working as expected.
Comment #32
Krzysztof DomańskiComment #34
Krzysztof DomańskiComment #35
dagmarMy concerns from #25, #27 and #31 are now addressed.
Thanks @Krzysztof Domański.
Comment #36
geek-merlinCool!
Comment #37
catchNeeds a re-roll.
Comment #38
Krzysztof DomańskiRe-rolled. The code below has been added by #2228741: Replace calls to format_string() with Drupal\Component\Render\FormattableMarkup.
Comment #39
Krzysztof DomańskiComment #40
Anonymous (not verified) CreditAttribution: Anonymous commented+1 rtbc
Comment #41
plachNice clean-up!
Additionally, we could consider the plain
%type: @message in %function (line %line of %file).
message to cover alsowatchdog_exception()
.Anyway, it would be safer to ensure that
$variables['@backtrace_string']
is set to avoid further notices. Setting NW for this.Also, minor: let's use
===
here.We could use
ErrorTestController::class
here and concatenate it with->generateWarnings()
.Comment #42
Krzysztof Domański@plach Thanks for feedback. I fixed #41.2.
I think we should address this problem in a separate issue, because it is out of scope. We should only improve the display of error backtrace here. Can you open a new issue for #41.1?
Comment #43
plachThanks for the update!
I don't think what I mentioned above is out of scope and thus deserves a new issue: the goal of this issue is to render backtraces correctly and
watchdog_exception()
is just another instance where the backtrace is rendered incorrectly (it's completely missing).I mistakingly said that failing to check that
@backtrace_string
is set could trigger notices where in fact it wouldn't, however it would be a way to reinforce that we're actually dealing with the intended log event, since we're forced to check the message to recognize them. The added check would provide a bit more confidence that we are dealing with the intended case.In short I'm proposing something like this:
Comment #44
Krzysztof DomańskiComment #45
plachThis won't work with the
watchdog_exception()
message, which has a trailing dot instead of the@backtrace_string
bit (see #41). If we want to avoid the regexp we could list the two supported messages explicitly and usein_array
.Comment #46
plachOr we could do
strpos($row->message, '%type: @message in %function (line %line of %file)') === 0
.Comment #47
Krzysztof DomańskiComment #48
plachLooks good, thanks!
I wish there were a more reliable way to identify relevant log entries, however this is a nice improvement over the current situation.
Comment #50
Krzysztof DomańskiRerolled
Comment #51
longwaveIs it worth opening a separate issue to refactor
%type: @message in %function (line %line of %file).
to a constant somewhere? This string appears at least 15 times in the codebase.Comment #53
Krzysztof Domański#52 Unrelated random test failure. Back to RTBC.
Comment #54
SpokjeBack to RTBC as per #48
Poor TestBot,
lost the plot,
created a fluke fail (so Needs Work this does not).
(Yes, it's "Sinterklaas" in The Netherlands on Dec. 5th, and you need to hand out stupid rhymes along with stupid gifts...)
EDIT: Meh, I'm way too slow for @Krzysztof Domański
Comment #55
alexpottTo preserve the translation and not to foist extra work on the translator I'd do this a bit differently. We can do:
Also this means that the wherever
@backtrace_string
has been used in custom errors it'll now appear nicely as well. This code could do with a comment.Comment #56
Krzysztof DomańskiComment #57
dagmar@Krzysztof Domański Thanks! I think the comment is missing
Comment #58
geek-merlin#51;
> Is it worth opening a separate issue to refactor %type: @message in %function (line %line of %file). to a constant somewhere? This string appears at least 15 times in the codebase.
Yes, let us roll this home and address that cleanup in a separate issue. This is related to #2932518: Deprecate watchdog_exception which defines Error::DEFAULT_ERROR_MESSAGE and does:
Comment #59
alexpottActually looking at the current code I think it is good to go. All we need is an RTBC :)
Comment #60
dagmarTested locally. working as expected.
Comment #61
alexpottCommitted and pushed 010c63bc66 to 9.0.x and f52c5af6f5 to 8.9.x. Thanks!
Going to ask other committers about backporting this. It make reading errors in logs simpler which has to be a good thing.
Comment #64
SpokjeIf the ancient Clan of Other Committers would decide on backporting this to D8.8 (which I really hope), patch #56 which was committed on D8.9 applies cleanly (and greenly) on the (current) latest D8.8.x-dev: https://www.drupal.org/pift-ci-job/1510080
Comment #65
alexpott@catch +1'd the backport.
Comment #68
geek-merlin