mirror of
https://github.com/filp/whoops.git
synced 2026-08-31 04:27:52 +00:00
Merge pull request #596 from florianorben/593-display-list-of-prev-exception-msgs
Display messages from previous exceptions
This commit is contained in:
@@ -25,6 +25,11 @@ class Inspector
|
||||
*/
|
||||
private $previousExceptionInspector;
|
||||
|
||||
/**
|
||||
* @var \Throwable[]
|
||||
*/
|
||||
private $previousExceptions;
|
||||
|
||||
/**
|
||||
* @param \Throwable $exception The exception to inspect
|
||||
*/
|
||||
@@ -57,6 +62,28 @@ class Inspector
|
||||
return $this->extractDocrefUrl($this->exception->getMessage())['message'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getPreviousExceptionMessages()
|
||||
{
|
||||
return array_map(function ($prev) {
|
||||
/** @var \Throwable $prev */
|
||||
return $this->extractDocrefUrl($prev->getMessage())['message'];
|
||||
}, $this->getPreviousExceptions());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[]
|
||||
*/
|
||||
public function getPreviousExceptionCodes()
|
||||
{
|
||||
return array_map(function ($prev) {
|
||||
/** @var \Throwable $prev */
|
||||
return $prev->getCode();
|
||||
}, $this->getPreviousExceptions());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a url to the php-manual related to the underlying error - when available.
|
||||
*
|
||||
@@ -117,6 +144,26 @@ class Inspector
|
||||
return $this->previousExceptionInspector;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array of all previous exceptions for this inspector's exception
|
||||
* @return \Throwable[]
|
||||
*/
|
||||
public function getPreviousExceptions()
|
||||
{
|
||||
if ($this->previousExceptions === null) {
|
||||
$this->previousExceptions = [];
|
||||
|
||||
$prev = $this->exception->getPrevious();
|
||||
while ($prev !== null) {
|
||||
$this->previousExceptions[] = $prev;
|
||||
$prev = $prev->getPrevious();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->previousExceptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator for the inspected exception's
|
||||
* frames.
|
||||
@@ -188,7 +235,7 @@ class Inspector
|
||||
*
|
||||
* If xdebug is installed
|
||||
*
|
||||
* @param \Throwable $exception
|
||||
* @param \Throwable $e
|
||||
* @return array
|
||||
*/
|
||||
protected function getTrace($e)
|
||||
|
||||
@@ -205,16 +205,18 @@ class PrettyPageHandler extends Handler
|
||||
"frame_code" => $this->getResource("views/frame_code.html.php"),
|
||||
"env_details" => $this->getResource("views/env_details.html.php"),
|
||||
|
||||
"title" => $this->getPageTitle(),
|
||||
"name" => explode("\\", $inspector->getExceptionName()),
|
||||
"message" => $inspector->getExceptionMessage(),
|
||||
"docref_url" => $inspector->getExceptionDocrefUrl(),
|
||||
"code" => $code,
|
||||
"plain_exception" => Formatter::formatExceptionPlain($inspector),
|
||||
"frames" => $frames,
|
||||
"has_frames" => !!count($frames),
|
||||
"handler" => $this,
|
||||
"handlers" => $this->getRun()->getHandlers(),
|
||||
"title" => $this->getPageTitle(),
|
||||
"name" => explode("\\", $inspector->getExceptionName()),
|
||||
"message" => $inspector->getExceptionMessage(),
|
||||
"previousMessages" => $inspector->getPreviousExceptionMessages(),
|
||||
"docref_url" => $inspector->getExceptionDocrefUrl(),
|
||||
"code" => $code,
|
||||
"previousCodes" => $inspector->getPreviousExceptionCodes(),
|
||||
"plain_exception" => Formatter::formatExceptionPlain($inspector),
|
||||
"frames" => $frames,
|
||||
"has_frames" => !!count($frames),
|
||||
"handler" => $this,
|
||||
"handlers" => $this->getRun()->getHandlers(),
|
||||
|
||||
"active_frames_tab" => count($frames) && $frames->offsetGet(0)->isApplication() ? 'application' : 'all',
|
||||
"has_frames_tabs" => $this->getApplicationPaths(),
|
||||
|
||||
@@ -52,7 +52,7 @@ header {
|
||||
color: #bebebe;
|
||||
font-size: 14px;
|
||||
}
|
||||
.exc-title-primary {
|
||||
.exc-title-primary, .exc-title-secondary {
|
||||
color: #e95353;
|
||||
}
|
||||
|
||||
@@ -70,6 +70,25 @@ header {
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
.prev-exc-title {
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.prev-exc-title + ul {
|
||||
margin: 0;
|
||||
padding: 0 0 0 20px;
|
||||
line-height: 12px;
|
||||
}
|
||||
|
||||
.prev-exc-title + ul li {
|
||||
font: 12px "Helvetica Neue", helvetica, arial, sans-serif;
|
||||
}
|
||||
|
||||
.prev-exc-title + ul li .prev-exc-code {
|
||||
display: inline-block;
|
||||
color: #bebebe;
|
||||
}
|
||||
|
||||
.details-container {
|
||||
left: 30%;
|
||||
width: 70%;
|
||||
|
||||
@@ -15,6 +15,25 @@
|
||||
<div class="exc-message">
|
||||
<?php if (!empty($message)): ?>
|
||||
<span><?php echo $tpl->escape($message) ?></span>
|
||||
|
||||
|
||||
<?php if (count($previousMessages)): ?>
|
||||
<div class="exc-title prev-exc-title">
|
||||
<span class="exc-title-secondary">Previous exceptions</span>
|
||||
</div>
|
||||
|
||||
<ul>
|
||||
<?php foreach ($previousMessages as $i => $previousMessage): ?>
|
||||
<li>
|
||||
<?php echo $tpl->escape($previousMessage) ?>
|
||||
<span class="prev-exc-code">(<?php echo $previousCodes[$i] ?>)</span>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
|
||||
|
||||
|
||||
<?php else: ?>
|
||||
<span class="exc-message-empty-notice">No message</span>
|
||||
<?php endif ?>
|
||||
|
||||
@@ -119,4 +119,68 @@ class InspectorTest extends TestCase
|
||||
|
||||
$this->assertFalse($inspector->hasPreviousException());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\Inspector::getPreviousExceptions
|
||||
*/
|
||||
public function testGetPreviousExceptionsReturnsListOfExceptions()
|
||||
{
|
||||
$exception1 = $this->getException('My first exception');
|
||||
$exception2 = $this->getException('My second exception', 0, $exception1);
|
||||
$exception3 = $this->getException('And the third one', 0, $exception2);
|
||||
|
||||
$inspector = $this->getInspectorInstance($exception3);
|
||||
|
||||
$previousExceptions = $inspector->getPreviousExceptions();
|
||||
$this->assertCount(2, $previousExceptions);
|
||||
$this->assertEquals($exception2, $previousExceptions[0]);
|
||||
$this->assertEquals($exception1, $previousExceptions[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\Inspector::getPreviousExceptions
|
||||
*/
|
||||
public function testGetPreviousExceptionsReturnsEmptyListIfThereAreNoPreviousExceptions()
|
||||
{
|
||||
$exception = $this->getException('My exception');
|
||||
$inspector = $this->getInspectorInstance($exception);
|
||||
|
||||
$previousExceptions = $inspector->getPreviousExceptions();
|
||||
$this->assertCount(0, $previousExceptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\Inspector::getPreviousExceptionMessages
|
||||
*/
|
||||
public function testGetPreviousExceptionMessages()
|
||||
{
|
||||
$exception1 = $this->getException('My first exception');
|
||||
$exception2 = $this->getException('My second exception', 0, $exception1);
|
||||
$exception3 = $this->getException('And the third one', 0, $exception2);
|
||||
|
||||
$inspector = $this->getInspectorInstance($exception3);
|
||||
|
||||
$previousExceptions = $inspector->getPreviousExceptionMessages();
|
||||
|
||||
$this->assertEquals($exception2->getMessage(), $previousExceptions[0]);
|
||||
$this->assertEquals($exception1->getMessage(), $previousExceptions[1]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\Inspector::getPreviousExceptionCodes
|
||||
*/
|
||||
public function testGetPreviousExceptionCodes()
|
||||
{
|
||||
$exception1 = $this->getException('My first exception', 99);
|
||||
$exception2 = $this->getException('My second exception', 20, $exception1);
|
||||
$exception3 = $this->getException('And the third one', 10, $exception2);
|
||||
|
||||
$inspector = $this->getInspectorInstance($exception3);
|
||||
|
||||
$previousExceptions = $inspector->getPreviousExceptionCodes();
|
||||
|
||||
$this->assertEquals($exception2->getCode(), $previousExceptions[0]);
|
||||
$this->assertEquals($exception1->getCode(), $previousExceptions[1]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user