Commit f72c451c by Qiang Xue

Display debug toolbar on error pages.

parent 1398de3f
...@@ -475,6 +475,8 @@ abstract class Application extends Module ...@@ -475,6 +475,8 @@ abstract class Application extends Module
*/ */
public function handleFatalError() public function handleFatalError()
{ {
unset($this->_memoryReserve);
// load ErrorException manually here because autoloading them will not work // load ErrorException manually here because autoloading them will not work
// when error occurs while autoloading a class // when error occurs while autoloading a class
if (!class_exists('\\yii\\base\\Exception', false)) { if (!class_exists('\\yii\\base\\Exception', false)) {
...@@ -487,7 +489,6 @@ abstract class Application extends Module ...@@ -487,7 +489,6 @@ abstract class Application extends Module
$error = error_get_last(); $error = error_get_last();
if (ErrorException::isFatalError($error)) { if (ErrorException::isFatalError($error)) {
unset($this->_memoryReserve);
$exception = new ErrorException($error['message'], $error['type'], $error['type'], $error['file'], $error['line']); $exception = new ErrorException($error['message'], $error['type'], $error['type'], $error['file'], $error['line']);
// use error_log because it's too late to use Yii log // use error_log because it's too late to use Yii log
error_log($exception); error_log($exception);
......
...@@ -192,11 +192,16 @@ class ErrorHandler extends Component ...@@ -192,11 +192,16 @@ class ErrorHandler extends Component
*/ */
public function renderFile($_file_, $_params_) public function renderFile($_file_, $_params_)
{ {
ob_start(); $_params_['handler'] = $this;
ob_implicit_flush(false); if ($this->exception instanceof ErrorException) {
extract($_params_, EXTR_OVERWRITE); ob_start();
require(Yii::getAlias($_file_)); ob_implicit_flush(false);
return ob_get_clean(); extract($_params_, EXTR_OVERWRITE);
require(Yii::getAlias($_file_));
return ob_get_clean();
} else {
return Yii::$app->getView()->renderFile($_file_, $_params_, $this);
}
} }
/** /**
......
...@@ -8,19 +8,19 @@ ...@@ -8,19 +8,19 @@
* @var string[] $lines * @var string[] $lines
* @var integer $begin * @var integer $begin
* @var integer $end * @var integer $end
* @var \yii\base\ErrorHandler $this * @var \yii\base\ErrorHandler $handler
*/ */
?> ?>
<li class="<?php if (!$this->isCoreFile($file) || $index === 1) echo 'application'; ?> call-stack-item" <li class="<?php if (!$handler->isCoreFile($file) || $index === 1) echo 'application'; ?> call-stack-item"
data-line="<?php echo (int)($line - $begin); ?>"> data-line="<?php echo (int)($line - $begin); ?>">
<div class="element-wrap"> <div class="element-wrap">
<div class="element"> <div class="element">
<span class="item-number"><?php echo (int)$index; ?>.</span> <span class="item-number"><?php echo (int)$index; ?>.</span>
<span class="text"><?php if ($file !== null) echo 'in ' . $this->htmlEncode($file); ?></span> <span class="text"><?php if ($file !== null) echo 'in ' . $handler->htmlEncode($file); ?></span>
<?php if ($method !== null): ?> <?php if ($method !== null): ?>
<span class="call"> <span class="call">
<?php if ($file !== null) echo '&ndash;' ?> <?php if ($file !== null) echo '&ndash;' ?>
<?php if ($class !== null) echo $this->addTypeLinks($class) . '::'; ?><?php echo $this->addTypeLinks($method . '()'); ?> <?php if ($class !== null) echo $handler->addTypeLinks($class) . '::'; ?><?php echo $handler->addTypeLinks($method . '()'); ?>
</span> </span>
<?php endif; ?> <?php endif; ?>
<span class="at"><?php if ($line !== null) echo 'at line'; ?></span> <span class="at"><?php if ($line !== null) echo 'at line'; ?></span>
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
<pre><?php <pre><?php
// fill empty lines with a whitespace to avoid rendering problems in opera // fill empty lines with a whitespace to avoid rendering problems in opera
for ($i = $begin; $i <= $end; ++$i) { for ($i = $begin; $i <= $end; ++$i) {
echo (trim($lines[$i]) == '') ? " \n" : $this->htmlEncode($lines[$i]); echo (trim($lines[$i]) == '') ? " \n" : $handler->htmlEncode($lines[$i]);
} }
?></pre> ?></pre>
</div> </div>
......
<?php <?php
/** /**
* @var \Exception $exception * @var \Exception $exception
* @var \yii\base\ErrorHandler $this * @var \yii\base\ErrorHandler $handler
*/ */
$title = $this->htmlEncode($exception instanceof \yii\base\Exception ? $exception->getName() : get_class($exception)); $title = $handler->htmlEncode($exception instanceof \yii\base\Exception ? $exception->getName() : get_class($exception));
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
...@@ -50,16 +50,17 @@ $title = $this->htmlEncode($exception instanceof \yii\base\Exception ? $exceptio ...@@ -50,16 +50,17 @@ $title = $this->htmlEncode($exception instanceof \yii\base\Exception ? $exceptio
</head> </head>
<body> <body>
<h1><?php echo $title?></h1> <h1><?php echo $title?></h1>
<h2><?php echo nl2br($this->htmlEncode($exception->getMessage()))?></h2> <h2><?php echo nl2br($handler->htmlEncode($exception->getMessage()))?></h2>
<p> <p>
The above error occurred while the Web server was processing your request. The above error occurred while the Web server was processing your request.
</p> </p>
<p> <p>
Please contact us if you think this is a server error. Thank you. Please contact us if you think this is a server error. Thank you.
</p> </p>
<div class="version"> <div class="version">
<?php echo date('Y-m-d H:i:s', time())?> <?php echo date('Y-m-d H:i:s', time())?>
</div> </div>
<?php if (method_exists($this, 'endBody')) $this->endBody(); // to allow injecting code into body (mostly by Yii Debug Toolbar) ?>
</body> </body>
</html> </html>
<?php <?php
/** /**
* @var \yii\base\Exception $exception * @var \yii\base\Exception $exception
* @var \yii\base\ErrorHandler $this * @var \yii\base\ErrorHandler $handler
*/ */
?> ?>
<div class="previous"> <div class="previous">
...@@ -9,13 +9,13 @@ ...@@ -9,13 +9,13 @@
<h2> <h2>
<span>Caused by:</span> <span>Caused by:</span>
<?php if ($exception instanceof \yii\base\Exception): ?> <?php if ($exception instanceof \yii\base\Exception): ?>
<span><?php echo $this->htmlEncode($exception->getName()); ?></span> &ndash; <span><?php echo $handler->htmlEncode($exception->getName()); ?></span> &ndash;
<?php echo $this->addTypeLinks(get_class($exception)); ?> <?php echo $handler->addTypeLinks(get_class($exception)); ?>
<?php else: ?> <?php else: ?>
<span><?php echo $this->htmlEncode(get_class($exception)); ?></span> <span><?php echo $handler->htmlEncode(get_class($exception)); ?></span>
<?php endif; ?> <?php endif; ?>
</h2> </h2>
<h3><?php echo $this->htmlEncode($exception->getMessage()); ?></h3> <h3><?php echo $handler->htmlEncode($exception->getMessage()); ?></h3>
<p>in <span class="file"><?php echo $exception->getFile(); ?></span> at line <span class="line"><?php echo $exception->getLine(); ?></span></p> <p>in <span class="file"><?php echo $exception->getFile(); ?></span> at line <span class="line"><?php echo $exception->getLine(); ?></span></p>
<?php echo $this->renderPreviousExceptions($exception); ?> <?php echo $handler->renderPreviousExceptions($exception); ?>
</div> </div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment