Skip to content

Commit bc504d9

Browse files
committed
format stack trace
1 parent 0e85d4c commit bc504d9

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

resources/views/error.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
# {{ $exception ? $exception->getLine() : "" }}
1010

1111
## Trace :
12-
# {{ $exception ? $exception->getTraceAsString() : "" }}
12+
# {{ $exception || $stackTrace ? $stackTrace : "" }}
1313
</x-mail::message>

src/Notifications/ErrorOccurred.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,31 @@ public function __construct($exception)
2020

2121
public function build()
2222
{
23+
$stackTrace = $this->formatStackTrace($this->exception);
24+
2325
return $this->subject(config('error-mailer.email.subject'))
2426
->markdown('errorMailer::error')
25-
->with(['exception' => $this->exception]);
27+
->with(['exception' => $this->exception, 'stackTrace' => $stackTrace]);
28+
}
29+
30+
function formatStackTrace($exception) {
31+
$trace = $exception->getTraceAsString();
32+
$traceLines = explode("\n", $trace);
33+
$formattedTrace = [];
34+
35+
foreach ($traceLines as $line) {
36+
// Extraction des informations clés de chaque ligne
37+
if (preg_match('/^#(\d+) (.*?):(.*)$/', $line, $matches)) {
38+
$number = $matches[1];
39+
$path = trim($matches[2]);
40+
$detail = trim($matches[3]);
41+
42+
// Formatage de chaque entrée de la stack trace
43+
$formattedLine = "### $number $path\n$detail\n";
44+
$formattedTrace[] = $formattedLine;
45+
}
46+
}
47+
48+
return implode("\n", $formattedTrace);
2649
}
2750
}

0 commit comments

Comments
 (0)