Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5e7410a

Browse files
committed
Improve Error message stacktrace style
Fixes #17326 Signed-off-by: Maurício Meneghini Fauth <[email protected]>
1 parent 745c39b commit 5e7410a

File tree

3 files changed

+36
-43
lines changed

3 files changed

+36
-43
lines changed

libraries/classes/Error.php

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -354,62 +354,52 @@ public function getTitle(): string
354354
*/
355355
public function getBacktraceDisplay(): string
356356
{
357-
return self::formatBacktrace(
358-
$this->getBacktrace(),
359-
"<br>\n",
360-
"<br>\n"
361-
);
357+
return self::formatBacktrace($this->getBacktrace());
362358
}
363359

364360
/**
365361
* return formatted backtrace field
366362
*
367-
* @param array $backtrace Backtrace data
368-
* @param string $separator Arguments separator to use
369-
* @param string $lines Lines separator to use
363+
* @param array $backtrace Backtrace data
370364
*
371365
* @return string formatted backtrace
372366
*/
373-
public static function formatBacktrace(
374-
array $backtrace,
375-
string $separator,
376-
string $lines
377-
): string {
378-
$retval = '';
367+
public static function formatBacktrace(array $backtrace): string
368+
{
369+
$retval = '<ol class="list-group">';
379370

380371
foreach ($backtrace as $step) {
372+
$retval .= '<li class="list-group-item">';
381373
if (isset($step['file'], $step['line'])) {
382-
$retval .= self::relPath($step['file'])
383-
. '#' . $step['line'] . ': ';
374+
$retval .= self::relPath($step['file']) . '#' . $step['line'] . ': ';
384375
}
385376

386377
if (isset($step['class'])) {
387378
$retval .= $step['class'] . $step['type'];
388379
}
389380

390-
$retval .= self::getFunctionCall($step, $separator);
391-
$retval .= $lines;
381+
$retval .= self::getFunctionCall($step);
382+
$retval .= '</li>';
392383
}
393384

394-
return $retval;
385+
return $retval . '</ol>';
395386
}
396387

397388
/**
398389
* Formats function call in a backtrace
399390
*
400-
* @param array $step backtrace step
401-
* @param string $separator Arguments separator to use
391+
* @param array $step backtrace step
402392
*/
403-
public static function getFunctionCall(array $step, string $separator): string
393+
public static function getFunctionCall(array $step): string
404394
{
405395
$retval = $step['function'] . '(';
406396
if (isset($step['args'])) {
407397
if (count($step['args']) > 1) {
408-
$retval .= $separator;
398+
$retval .= '<br>';
409399
foreach ($step['args'] as $arg) {
410400
$retval .= "\t";
411401
$retval .= $arg;
412-
$retval .= ',' . $separator;
402+
$retval .= ',<br>';
413403
}
414404
} elseif (count($step['args']) > 0) {
415405
foreach ($step['args'] as $arg) {
@@ -481,12 +471,12 @@ public function getDisplay(): string
481471

482472
return $template->render('error/get_display', [
483473
'context' => $context,
484-
'isUserError' => $this->isUserError(),
474+
'is_user_error' => $this->isUserError(),
485475
'type' => $this->getType(),
486476
'file' => $this->getFile(),
487477
'line' => $this->getLine(),
488478
'message' => $this->getMessage(),
489-
'backtraceDisplay' => $this->getBacktraceDisplay(),
479+
'formatted_backtrace' => $this->getBacktraceDisplay(),
490480
]);
491481
}
492482

templates/error/get_display.twig

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
<div class="alert alert-{{ context }}" role="alert">
2+
{%- if not is_user_error -%}
3+
<p><strong>{{ type }}</strong> in {{ file }}#{{ line }}</p>
4+
{%- endif -%}
25

3-
{%- if isUserError == false %}
4-
<strong>{{ type }}</strong> in {{ file ~'#'~ line }} <br>
5-
{% endif -%}
6+
{{ message|raw }}
67

7-
{{ message }}
8-
9-
{% if isUserError == false %}
10-
<br><br>
11-
<strong>Backtrace</strong><br>
12-
<br>
13-
{{ backtraceDisplay }}
14-
{% endif %}
15-
16-
17-
</div>
8+
{%- if not is_user_error -%}
9+
<p class="mt-3"><strong>Backtrace</strong></p>
10+
{{- formatted_backtrace|raw -}}
11+
{%- endif -%}
12+
</div>

test/classes/ErrorTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function testGetHash(): void
120120
public function testGetBacktraceDisplay(): void
121121
{
122122
$this->assertStringContainsString(
123-
'PHPUnit\Framework\TestResult->run(<Class:PhpMyAdmin\Tests\ErrorTest>)<br>',
123+
'PHPUnit\Framework\TestResult->run(<Class:PhpMyAdmin\Tests\ErrorTest>)',
124124
$this->object->getBacktraceDisplay()
125125
);
126126
}
@@ -130,10 +130,18 @@ public function testGetBacktraceDisplay(): void
130130
*/
131131
public function testGetDisplay(): void
132132
{
133+
$actual = $this->object->getDisplay();
134+
$this->assertStringStartsWith(
135+
'<div class="alert alert-danger" role="alert"><p><strong>Warning</strong> in error.txt#15</p>'
136+
. '<img src="themes/dot.gif" title="" alt="" class="icon ic_s_error"> Compile Error'
137+
. '<p class="mt-3"><strong>Backtrace</strong></p><ol class="list-group"><li class="list-group-item">',
138+
$actual
139+
);
133140
$this->assertStringContainsString(
134-
'<div class="alert alert-danger" role="alert"> <strong>Warning</strong>',
135-
$this->object->getDisplay()
141+
'PHPUnit\Framework\TestResult->run(<Class:PhpMyAdmin\Tests\ErrorTest>)</li><li class="list-group-item">',
142+
$actual
136143
);
144+
$this->assertStringEndsWith('</li></ol></div>' . "\n", $actual);
137145
}
138146

139147
/**

0 commit comments

Comments
 (0)