You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

error_exception.php 2.0KB

2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. use CodeIgniter\CLI\CLI;
  3. // The main Exception
  4. CLI::newLine();
  5. CLI::write('[' . get_class($exception) . ']', 'light_gray', 'red');
  6. CLI::newLine();
  7. CLI::write($message);
  8. CLI::newLine();
  9. CLI::write('at ' . CLI::color(clean_path($exception->getFile()) . ':' . $exception->getLine(), 'green'));
  10. CLI::newLine();
  11. // The backtrace
  12. if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE) {
  13. $backtraces = $exception->getTrace();
  14. if ($backtraces) {
  15. CLI::write('Backtrace:', 'green');
  16. }
  17. foreach ($backtraces as $i => $error) {
  18. $padFile = ' '; // 4 spaces
  19. $padClass = ' '; // 7 spaces
  20. $c = str_pad($i + 1, 3, ' ', STR_PAD_LEFT);
  21. if (isset($error['file'])) {
  22. $filepath = clean_path($error['file']) . ':' . $error['line'];
  23. CLI::write($c . $padFile . CLI::color($filepath, 'yellow'));
  24. } else {
  25. CLI::write($c . $padFile . CLI::color('[internal function]', 'yellow'));
  26. }
  27. $function = '';
  28. if (isset($error['class'])) {
  29. $type = ($error['type'] === '->') ? '()' . $error['type'] : $error['type'];
  30. $function .= $padClass . $error['class'] . $type . $error['function'];
  31. } elseif (! isset($error['class']) && isset($error['function'])) {
  32. $function .= $padClass . $error['function'];
  33. }
  34. $args = implode(', ', array_map(static function ($value) {
  35. switch (true) {
  36. case is_object($value):
  37. return 'Object(' . get_class($value) . ')';
  38. case is_array($value):
  39. return count($value) ? '[...]' : '[]';
  40. case $value === null:
  41. return 'null'; // return the lowercased version
  42. default:
  43. return var_export($value, true);
  44. }
  45. }, array_values($error['args'] ?? [])));
  46. $function .= '(' . $args . ')';
  47. CLI::write($function);
  48. CLI::newLine();
  49. }
  50. }