|
2 | 2 |
|
3 | 3 | namespace Spatie\LaravelIgnition\Views;
|
4 | 4 |
|
5 |
| -use Exception; |
6 | 5 | use Illuminate\Contracts\View\Engine;
|
7 | 6 | use Illuminate\Foundation\Application;
|
8 | 7 | use Illuminate\Support\Arr;
|
|
19 | 18 | class ViewExceptionMapper
|
20 | 19 | {
|
21 | 20 | protected Engine $compilerEngine;
|
| 21 | + |
22 | 22 | protected BladeSourceMapCompiler $bladeSourceMapCompiler;
|
| 23 | + |
23 | 24 | protected array $knownPaths;
|
24 | 25 |
|
25 | 26 | public function __construct(BladeSourceMapCompiler $bladeSourceMapCompiler)
|
@@ -80,15 +81,27 @@ protected function createException(Throwable $baseException): IgnitionViewExcept
|
80 | 81 |
|
81 | 82 | protected function modifyViewsInTrace(IgnitionViewException $exception): void
|
82 | 83 | {
|
| 84 | + $viewIndex = null; |
| 85 | + |
83 | 86 | $trace = Collection::make($exception->getPrevious()->getTrace())
|
84 |
| - ->map(function ($trace) { |
| 87 | + ->map(function ($trace, $index) use (&$viewIndex) { |
85 | 88 | if ($originalPath = $this->findCompiledView(Arr::get($trace, 'file', ''))) {
|
| 89 | + |
86 | 90 | $trace['file'] = $originalPath;
|
87 | 91 | $trace['line'] = $this->getBladeLineNumber($trace['file'], $trace['line']);
|
| 92 | + |
| 93 | + if ($viewIndex === null) { |
| 94 | + $viewIndex = $index; |
| 95 | + } |
88 | 96 | }
|
89 | 97 |
|
90 | 98 | return $trace;
|
91 |
| - })->toArray(); |
| 99 | + }) |
| 100 | + ->when( |
| 101 | + $viewIndex !== null && str_ends_with($exception->getFile(), '.blade.php'), |
| 102 | + fn (Collection $trace) => $trace->slice($viewIndex + 1) // Remove all traces before the view |
| 103 | + ) |
| 104 | + ->toArray(); |
92 | 105 |
|
93 | 106 | $traceProperty = new ReflectionProperty('Exception', 'trace');
|
94 | 107 | $traceProperty->setAccessible(true);
|
|
0 commit comments