You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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):
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?
@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 👍
How can I handle
Runtime Exceptions
inside$onRejected
part of->then()
method after querying database? I think there's a important piece missing insidefirends-of-reactphp/mysql
and that is exception handling!If something goes wrong with
mysql server
andRuntime Exception
occurs the whole system crashes down apart! Here's the error message I get in these type of situations...Where is the bug? I think it's somewhere around (or I'm doing something wrong):
mysql/src/Io/Connection.php
Line 220 in 7b4428d
And this is how I query database:
Can anyone else check and verify this issue exists in
mysql 8.0
andfriends-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
The text was updated successfully, but these errors were encountered: