Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 39
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2
3use CodeIgniter\CLI\CLI;
4
5// The main Exception
6CLI::write('[' . $exception::class . ']', 'light_gray', 'red');
7CLI::write($message);
8CLI::write('at ' . CLI::color(clean_path($exception->getFile()) . ':' . $exception->getLine(), 'green'));
9CLI::newLine();
10
11$last = $exception;
12
13while ($prevException = $last->getPrevious()) {
14    $last = $prevException;
15
16    CLI::write('  Caused by:');
17    CLI::write('  [' . $prevException::class . ']', 'red');
18    CLI::write('  ' . $prevException->getMessage());
19    CLI::write('  at ' . CLI::color(clean_path($prevException->getFile()) . ':' . $prevException->getLine(), 'green'));
20    CLI::newLine();
21}
22
23// The backtrace
24if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE) {
25    $backtraces = $last->getTrace();
26
27    if ($backtraces) {
28        CLI::write('Backtrace:', 'green');
29    }
30
31    foreach ($backtraces as $i => $error) {
32        $padFile  = '    '; // 4 spaces
33        $padClass = '       '; // 7 spaces
34        $c        = str_pad($i + 1, 3, ' ', STR_PAD_LEFT);
35
36        if (isset($error['file'])) {
37            $filepath = clean_path($error['file']) . ':' . $error['line'];
38
39            CLI::write($c . $padFile . CLI::color($filepath, 'yellow'));
40        } else {
41            CLI::write($c . $padFile . CLI::color('[internal function]', 'yellow'));
42        }
43
44        $function = '';
45
46        if (isset($error['class'])) {
47            $type = ($error['type'] === '->') ? '()' . $error['type'] : $error['type'];
48            $function .= $padClass . $error['class'] . $type . $error['function'];
49        } elseif (! isset($error['class']) && isset($error['function'])) {
50            $function .= $padClass . $error['function'];
51        }
52
53        $args = implode(', ', array_map(static fn ($value): string => match (true) {
54            is_object($value) => 'Object(' . $value::class . ')',
55            is_array($value)  => $value !== [] ? '[...]' : '[]',
56            $value === null   => 'null', // return the lowercased version
57            default           => var_export($value, true),
58        }, array_values($error['args'] ?? [])));
59
60        $function .= '(' . $args . ')';
61
62        CLI::write($function);
63        CLI::newLine();
64    }
65}