Hi,
current implementation of handleError method logs the error message at first, and then raises an event.
I believe the order should be reversed, so that one might extend the logged error message.
Let’s assume I want to assign each error occurrence an unique ID, which is displayed to user, so he might contact the developer providing the error code.
currently I’m just logging the error code in onError handler
'onError' => function($ev) {
$ev->params['uniqid'] = uniqid();
Yii::log($ev->params['uniqid'], 'error');
},
but under heavy load the order might be lost (assuming two separate requests being processed at once)
I’d love to do so:
$ev->message = $ev->params['uniqid'] . ': '. $ev->message;
here’s my proposition to modify the handleError()
// disable error capturing to avoid recursive errors
restore_error_handler();
restore_exception_handler();
// modifications begin
try
{
Yii::import('CErrorEvent',true);
$event=new CErrorEvent($this,$code,$message,$file,$line);
$this->onError($event);
if(!$event->handled)
{
// try an error handler
if(($handler=$this->getErrorHandler())!==null)
$handler->handle($event);
else
$this->displayError($code,$message,$file,$line);
}
}
catch(Exception $e)
{
$this->displayException($e);
}
$log="{$event->message} ($file:$line)\nStack trace:\n";
// end of modifications
$trace=debug_backtrace();