0

I am getting this error code:

PHP Warning: get_class() expects parameter 1 to be object, string given in /phalcon/vendor/clue/block-react/src/functions.php on line 90 PHP Fatal error: Uncaught UnexpectedValueException: Promise rejected with unexpected value of type in /phalcon/vendor/clue/block-react/src/functions.php:89 Stack trace:

  • 0 /phalcon/vendor/clue/block-react/src/functions.php(198): Clue\React\Block\await(NULL, Object(React\EventLoop\StreamSelectLoop), NULL)
  • 1 /phalcon/app/tasks/RunTask.php(96): Clue\React\Block\awaitAll(NULL, Object(React\EventLoop\StreamSelectLoop))

I'm building my promises with the following code:

$promises[] = $this->getTrades($rule->id, $exchange->id)
                ->then(
                    function ($trades) use ($handleTrades) {
                        foreach ($trades as $trade) {
                            $handleTrades[] = $trade;
                        }
                    }
                );

The function is like this:

private function getTrades($rule, $exchange) {
    $deferred = new React\Promise\Deferred();

    //...

    if (empty($trades->count())) {
        $deferred->reject("No trades found for rule $rule");
    } else {
        $deferred->resolve($trades);
    }

    return $deferred->promise();
}

How do I solve this?

Maarten Raaijmakers
  • 615
  • 2
  • 8
  • 20

2 Answers2

1

The real reason is Fatal error: Uncaught UnexpectedValueException, not the warning. As you can see the clue/reactphp-block library expects an Exception in your reject function. Try:

$deferred->reject(new \Exception("No trades found for rule $rule"));
Furgas
  • 2,729
  • 1
  • 18
  • 27
  • That removes the above error, now I'm getting PHP Fatal error: Uncaught Exception: No trades found for rule 1 in I'm not a master of Exceptions yet unfortunately – Maarten Raaijmakers Jul 24 '18 at 12:53
  • Well, that's not a problem we are capable to solve for you, at least with the code you provided. We have no idea what `$trades` is and where is it coming from. – Furgas Jul 24 '18 at 13:06
  • And you must clarify the problem. Is the problem that `$trades->count()` is 0, or is the problem that you're getting fatal error? If the former, then as I said, we can't help you with that code. If the latter, then you have to handle somehow this exception by adding a second parameter to `then` with a function that will print some message or whatever you want to happen in case of no trades. – Furgas Jul 24 '18 at 13:29
  • It's indeed when $trades->count() is 0 that it should throw the Exception. Not sure if that helps, but I'll tug around a bit. – Maarten Raaijmakers Jul 25 '18 at 07:29
0

As Furgas mentioned above I needed to add the error handling function in the promise.

Maarten Raaijmakers
  • 615
  • 2
  • 8
  • 20