Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with CakePHP: Uncaught RuntimeException: You cannot call all() on a non-select query. Use execute() instead. #492

Open
emaillenin opened this issue May 31, 2020 · 2 comments

Comments

@emaillenin
Copy link

emaillenin commented May 31, 2020

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

@emaillenin
Copy link
Author

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);
}

@emaillenin
Copy link
Author

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
    );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant