Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Problem
- When an exception is thrown during a entity storage controller
save()
operation, all you get is this fatal error:
Error message Exception: Serialization of 'Closure' is not allowed in serialize() (line 154 of \core\modules\dblog\dblog.module). The website has encountered an error. Please try again later.
- Whereas the dumping the entry that was supposed to be logged contains the actual error that may be this:
SQLSTATE[42S22]: Column not found: 1054 Unknown column ...
Cause
- The
$log_entry
being passed tohook_watchdog()
contains a'backtrace'
in its variables, which in turn contains the DrupalKernel/DI container and other classes and Closures that cannot be serialized. dblog_watchdog()
performs this:
'variables' => serialize($log_entry['variables']),
Comment | File | Size | Author |
---|---|---|---|
#1 | watchdog.backtrace.1.patch | 596 bytes | sun |
Comments
Comment #1
sunAttached patch at least shows the actual error message.
However, we might want to revisit whether it is a good idea to put the backtrace into those variables in the first place...?
We could add it to $log_entry itself instead of 'variables'? Or do you want to record the backtrace in the log message?
If so, we'd have to find a way to serialize a backtrace that contains objects that cannot be serialized.
That said, I'd bet that you actually want to log the string representation of the backtrace only?
Comment #2
das-peter CreditAttribution: das-peter commentedRelated: #1872690: Exception: Serialization of 'Closure' is not allowed in serialize
Comment #3
olli CreditAttribution: olli commentedDo you mean something like:
already in _drupal_decode_exception() instead of killing the backtrace everywhere?
Comment #4
tim.plunkettThat doesn't actually work, you get "Undefined index 'args'" in format_backtrace(). This is fine as is, and is holding up patches like #1952842: Views UI still uses NOT_USED for page callbacks
Comment #5
webchickI couldn't quite parse that comment, but Tim and I went back and forth a bit and came up with:
If that's not quite correct we can adjust it in a follow-up, but in the meantime this would unblock #1952842: Views UI still uses NOT_USED for page callbacks which is quite a silly problem to have.
Committed and pushed to 8.x. Thanks!
Comment #6
yched CreditAttribution: yched commentedCouldn't we rework format_backtrace() so that it only contains the function names in the callstack, without the arguments ?
Comment #7
olli CreditAttribution: olli commented@tim.plunkett: you are right. That is getting fixed in #1832300: Followup: Add backtrace to all errors - Notice undefined index 'args'.