Skip to content

Commit 47f2d5a

Browse files
committed
separate error in crash reports for easy viewing
1 parent 8c5ce81 commit 47f2d5a

2 files changed

Lines changed: 58 additions & 12 deletions

File tree

‎controllers/DevCP/ModerateCrashReportController.php‎

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717
use Slim\Exception\HttpBadRequestException;
1818
use Slim\Exception\HttpNotFoundException;
1919

20-
class ModerateCrashReportController {
20+
class ModerateCrashReportController
21+
{
2122

2223
public function listIndex(
2324
Request $request,
2425
Response $response,
2526
TwigEnvironment $twig,
2627
EntityManager $em
27-
){
28+
) {
2829
$response->getBody()->write(
2930
$twig->render('devcp/crash-report/crash-report.list.devcp.html.twig', [
30-
'crash_reports' => $em->getRepository(CrashReport::class)->findBy([],['id' => 'DESC'])
31+
'crash_reports' => $em->getRepository(CrashReport::class)->findBy([], ['id' => 'DESC'])
3132
])
3233
);
3334

@@ -41,19 +42,51 @@ public function view(
4142
EntityManager $em,
4243
FlashMessage $flash,
4344
$id
44-
){
45+
) {
46+
$error = [];
47+
4548
// Find crash report
4649
$crash_report = $em->getRepository(CrashReport::class)->find($id);
47-
if(!$crash_report){
50+
if (!$crash_report) {
4851
$flash->warning('Crash report not found.');
4952
$response = $response->withHeader('Location', '/dev/crash-report/list')->withStatus(302);
5053
return $response;
5154
}
5255

56+
57+
// Check if there is a game log
58+
$game_log = $crash_report->getGameLog();
59+
if ($game_log) {
60+
61+
// Check for error pattern
62+
$error_pattern = '/Exception ([0-9xa-fA-F]+) thrown\: ([0-9_A-Za-f]+)\nError\: (.+)/';
63+
if (\preg_match($error_pattern, $game_log, $error_matches)) {
64+
65+
$error = [
66+
'exception_code' => $error_matches[1],
67+
'identifier' => $error_matches[2],
68+
'error_message' => $error_matches[3],
69+
];
70+
71+
// Check for trace
72+
$trace_pattern = '/\[\#(\d+)\s?\]\s(.+)$/m';
73+
if (\preg_match_all($trace_pattern, $game_log, $trace_matches, PREG_PATTERN_ORDER)) {
74+
75+
$trace = [];
76+
for ($i = 0; $i < \count($trace_matches[0]); $i++) {
77+
$trace[(int)$trace_matches[1][$i]] = (string)$trace_matches[2][$i];
78+
}
79+
80+
$error['trace'] = $trace;
81+
}
82+
}
83+
}
84+
5385
// Show output
5486
$response->getBody()->write(
5587
$twig->render('devcp/crash-report/crash-report.devcp.html.twig', [
56-
'crash_report' => $crash_report
88+
'crash_report' => $crash_report,
89+
'error' => $error,
5790
])
5891
);
5992
return $response;
@@ -66,23 +99,23 @@ public function delete(
6699
EntityManager $em,
67100
FlashMessage $flash,
68101
$id
69-
){
102+
) {
70103
// Find crash report
71104
$crash_report = $em->getRepository(CrashReport::class)->find($id);
72-
if(!$crash_report){
105+
if (!$crash_report) {
73106
$flash->warning('Crash report not found.');
74107
$response = $response->withHeader('Location', '/dev/crash-report/list')->withStatus(302);
75108
return $response;
76109
}
77110

78111
// Delete savefile
79112
$save_filename = $crash_report->getSaveFilename();
80-
if($save_filename){
113+
if ($save_filename) {
81114
$dir = Config::get('storage.path.crash-report-savefile');
82-
if(\file_exists($dir)){
115+
if (\file_exists($dir)) {
83116
$filepath = $dir . '/' . $save_filename;
84-
if(\file_exists($filepath)){
85-
if(\unlink($filepath) === false){
117+
if (\file_exists($filepath)) {
118+
if (\unlink($filepath) === false) {
86119
throw new \Exception("failed to delete savefile: {$filepath}");
87120
}
88121
}

‎views/devcp/crash-report/crash-report.devcp.html.twig‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@
6464
<pre style="color: #ccc; background-color: #0D0D0D; border: 2px solid black; padding: 10px; margin: 0;">{{ crash_report.description }}</pre>
6565
{% endif %}
6666

67+
{% if error is not empty %}
68+
<h5 style="margin-top: 30px; border-bottom: 0;">Error</h5>
69+
<pre style="color: #ccc; background-color: #0D0D0D; border: 2px solid black; padding: 10px; margin: 0;">{{ error.identifier }} ({{ error.exception_code }})
70+
{{ error.error_message }}
71+
72+
{% for num, text in error.trace %}[#{{ num }}] {{ text }}
73+
{% endfor %}</pre>
74+
{% if error.trace is not empty %}
75+
<table class="table">
76+
</table>
77+
{% endif %}
78+
{% endif %}
79+
6780
<h5 style="margin-top: 30px; border-bottom: 0;">Technical Data</h5>
6881

6982
<div class="accordion" style="margin-top: 10px;">

0 commit comments

Comments
 (0)