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

Handling RuntimeException Inside $onRejected Promise #155

Closed
hasanparasteh opened this issue May 11, 2022 · 1 comment
Closed

Handling RuntimeException Inside $onRejected Promise #155

hasanparasteh opened this issue May 11, 2022 · 1 comment
Labels

Comments

@hasanparasteh
Copy link

hasanparasteh commented May 11, 2022

How can I handle Runtime Exceptions inside $onRejected part of ->then() method after querying database? I think there's a important piece missing inside firends-of-reactphp/mysql and that is exception handling!

If something goes wrong with mysql server and Runtime Exception occurs the whole system crashes down apart! Here's the error message I get in these type of situations...

{closure}(): Argument #1 ($error) must be of type React\MySQL\Exception, RuntimeException given, called in /home/user/app-name/vendor/react/promise/src/RejectedPromise.php on line 28

Where is the bug? I think it's somewhere around (or I'm doing something wrong):

throw new \RuntimeException(

And this is how I query database:

return $this->connection
    ->query($query)
    ->then(function (QueryResult $result) {
        // getting information about query
    }, function (Exception $error) {
        return [
            'result' => false,
            'line' => $error->getLine(),
            'error' => $error->getMessage(),
            'details' => $error->getTraceAsString(),
        ];
});

Can anyone else check and verify this issue exists in mysql 8.0 and friends-of-reactphp/mysql 0.5.6? can you try restarting your SQL server during a long running query and see if this happens to you too?

Also looking at: Detecting unhandled rejections

@clue
Copy link
Contributor

clue commented May 12, 2022

@hasanparasteh Thanks for reporting, this is an interesting one!

It looks like you're using the incorrect import use React\MySQL\Exception and should probably use the type signature \Exception $error or use the import use Exception instead.

I agree that this is an easy oversight and definitely something we should improve in the future! I'll take a look as this as part of #147 which is going to improve the API somewhat 👍

I hope this helps! I'll assume this is resolved and will close this for now, please feel free to report back otherwise 👍

@clue clue closed this as completed May 12, 2022
@clue clue added the question label May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants