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']),