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 to hook_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']),
    
CommentFileSizeAuthor
#1 watchdog.backtrace.1.patch596 bytessun
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sun’s picture

Status: Active » Needs review
FileSize
596 bytes

Attached 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?

das-peter’s picture

olli’s picture

I'd bet that you actually want to log the string representation of the backtrace only?

Do you mean something like:

-    'backtrace' => $backtrace,
+    '!backtrace' => format_backtrace($backtrace),

already in _drupal_decode_exception() instead of killing the backtrace everywhere?

tim.plunkett’s picture

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

That 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

webchick’s picture

Status: Reviewed & tested by the community » Fixed

I couldn't quite parse that comment, but Tim and I went back and forth a bit and came up with:

// Remove any backtraces since they may contain an unserializable variable.

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!

yched’s picture

Couldn't we rework format_backtrace() so that it only contains the function names in the callstack, without the arguments ?

olli’s picture

@tim.plunkett: you are right. That is getting fixed in #1832300: Followup: Add backtrace to all errors - Notice undefined index 'args'.

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