rollbar-php
rollbar-php copied to clipboard
Error with CakePHP: Uncaught RuntimeException: You cannot call all() on a non-select query. Use execute() instead.
I'm using the latest rollbar version (2.0.0). Rollbar has started throwing this exception recently. I could not find the relevant method from the stack trace.
Looks like Rollbar is trying the serialize the Query object involved in the exception (to include in the payload) and fails.
2020-05-31 20:30:03 Error: [Cake\Error\FatalErrorException] Uncaught RuntimeException: You cannot call all() on a non-select query. Use execute() instead. in /var/www/src/vendor/cakephp/cakephp/src/ORM/Query.php:1041
Stack trace:
#0 /var/www/src/vendor/cakephp/cakephp/src/Datasource/QueryTrait.php(141): Cake\ORM\Query->all()
#1 /var/www/src/vendor/rollbar/rollbar/src/Utilities.php(102): Cake\ORM\Query->getIterator()
#2 /var/www/src/vendor/rollbar/rollbar/src/Utilities.php(159): Rollbar\Utilities::serializeForRollbar(Object(Cake\ORM\Query), NULL, Array, -1, 2)
#3 /var/www/src/vendor/rollbar/rollbar/src/Utilities.php(105): Rollbar\Utilities::serializeObject(Object(Cake\ORM\Query), NULL, Array, -1, 1)
#4 /var/www/src/vendor/rollbar/rollbar/src/Utilities.php(117): Rollbar\Utilities::serializeForRollbar(Array, NULL, Array, -1, 1)
#5 /var/www/src/vendor/rollbar/rollbar/src/Payload/Frame.php(111): Rollbar\Utilities::serializeForRollbar(Array, NULL, Array)
#6 in /var/www/src/vendor/cakephp/cakephp/src/ORM/Query.php on line 1041
Stack Trace:
- /var/www/dev/src/Error/RollbarErrorHandlerTrait.php:50
- /var/www/dev/vendor/cakephp/cakephp/src/Error/BaseErrorHandler.php:122
- [main] - [internal], line ??
Workaround until this is fixed in Rollbar:
public function handleException(Throwable $exception): void
{
$this->log($exception->getMessage(), LogLevel::ERROR);
if ($exception instanceof PDOException) {
// Custom handling due to https://github.com/rollbar/rollbar-php/issues/492
// Do not use `getTrace` as that will generate another Fatal like above
Rollbar::log(Level::ERROR, $exception->getMessage(), ['stacktrace' => $exception->getTraceAsString()], true);
} else {
Rollbar::log(Level::ERROR, $exception);
}
parent::handleException($exception);
}
Another workaround (as a patch on rollbar/rollbar/src/Utilities.php) before the foreach in serializeForRollbar method:
if ($obj instanceof \Cake\ORM\Query) {
return self::serializeObject(
"Custom PDO error: " . $obj->sql(),
$customKeys,
$objectHashes,
$maxDepth,
$depth
);
}