@@ -46,24 +46,53 @@ function formatExceptionTrace(\\Throwable $e): string {
4646 $output .= "Stack trace:\\n";
4747
4848 $rawTrace = $e->getTrace();
49- $visibleFrameIndex = 0 ;
49+ $filteredFrames = [] ;
5050
5151 foreach ($rawTrace as $frame) {
5252 $frameFile = isset($frame['file']) ? sanitizePath($frame['file']) : '';
53- $frameLine = isset($frame['line']) ? "({$frame['line']})" : '';
53+ $frameLine = isset($frame['line']) ? $frame['line'] : null;
54+ $frameFunc = $frame['function'] ?? '';
55+ $frameClass = $frame['class'] ?? '';
5456
5557 if (
5658 $frameFile === '' ||
5759 str_contains($frameFile, 'runner.php') ||
5860 str_contains($frameFile, '/typephp/') ||
59- (isset($frame['class']) && str_starts_with($frame['class'] , 'TypePHP\\\\Internal\\\\') )
61+ str_starts_with($frameClass , 'TypePHP\\\\' )
6062 ) {
6163 continue;
6264 }
6365
66+ if ($frameFunc === '{closure}' || str_contains($frameFunc, '{closure')) {
67+ if ($frameLine !== null && $frameLine === $line) {
68+ continue;
69+ }
70+ if (!empty($frame['args']) && is_string($frame['args'][0] ?? null) && str_contains($frame['args'][0], '<')) {
71+ continue;
72+ }
73+ }
74+
75+ if ($frameLine !== null && $frameLine === $line && $frameFunc === '__construct') {
76+ continue;
77+ }
78+
79+ $filteredFrames[] = $frame;
80+ }
81+
82+ if (empty($filteredFrames)) {
83+ $output .= "#0 {main}\\n";
84+ $output .= " thrown in {$file} on line {$line}\\n";
85+ return $output;
86+ }
87+
88+ $visibleIndex = 0;
89+ foreach ($filteredFrames as $frame) {
90+ $frameFile = isset($frame['file']) ? sanitizePath($frame['file']) : $file;
91+ $frameLineStr = isset($frame['line']) ? "({$frame['line']})" : '';
92+
6493 $call = '';
6594 if (isset($frame['class'])) {
66- $call .= $frame['class'] . $frame['type'];
95+ $call .= $frame['class'] . ( $frame['type'] ?? '->') ;
6796 }
6897 $call .= ($frame['function'] ?? '{main}');
6998
@@ -84,11 +113,11 @@ function formatExceptionTrace(\\Throwable $e): string {
84113 $call .= '(' . implode(', ', $argsSummary) . ')';
85114 }
86115
87- $output .= "#{$visibleFrameIndex } {$frameFile}{$frameLine }: {$call}\\n";
88- $visibleFrameIndex ++;
116+ $output .= "#{$visibleIndex } {$frameFile}{$frameLineStr }: {$call}\\n";
117+ $visibleIndex ++;
89118 }
90119
91- $output .= "#{$visibleFrameIndex } {main}\\n";
120+ $output .= "#{$visibleIndex } {main}\\n";
92121 $output .= " thrown in {$file} on line {$line}\\n";
93122
94123 return $output;
0 commit comments