-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
No need to echo db exception #9212
Conversation
Why? |
how did you get this output? looks a bit like yii 1.1 error page... |
When no errorAction is set in the errorHandler config, the following view file is rendered: yiisoft/yii2/views/errorHandler/error.php. That's the one in the pic. BTW, a full stacktrace is shown in debug mode, with a longer version of the exception being echoed at the end of the page (because of echo $exception). |
echo was added in #1946 |
I've verified that in current code it seems to work just fine w/o echo. @cebe any comments? |
The echo part is intended for This works correctly though: Yii::$app->session->get('test');
sleep(5); // shutdown db server here
Yii::$app->session->set('test', 123); |
If there's no DB table it works correcty as well i.e. exception is handled properly. |
@samdark Yes it's handled, but not in Use this: Yii::$app->session->get('test');
sleep(5); // shutdown db server here
Yii::$app->session->set('test', 123); // will cause exception in writeSession
exit; This outputs the exception as string without rendering any html. And if you do // Shutdown db server here
Yii::$app->session->open();
exit; You get rendered html + the string at bottom. Dirty fix could be: // Only echo and log if we haven't processed an exception yet
if (Yii::$app->errorHandler->exception === null) {
$exception = ErrorHandler::convertExceptionToString($e);
// its too late to use Yii logging here
error_log($exception);
echo $exception;
} @cebe Is there really no way to properly handle exceptions thrown in |
however this issue has been worked around by fa845ee already. Closing this PR. |
related to #11726 |
No description provided.