From 7f041a9f93c07562ceceb75a0f68b01558b6d524 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 7 Dec 2019 22:53:59 +0000 Subject: [PATCH] have fatal_error print out a bunch more info when run from CLI --- core/util.php | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/core/util.php b/core/util.php index 0f005edb..48a4f1c1 100644 --- a/core/util.php +++ b/core/util.php @@ -523,10 +523,30 @@ function _fatal_error(Exception $e): void //$h_hash = $hash ? "

Hash: $hash" : ""; //'.$h_hash.' - $q = (!isset($e->query) || is_null($e->query)) ? "" : "

Query: " . html_escape($e->query); - header("HTTP/1.0 500 Internal Error"); - echo ' + if (PHP_SAPI === 'cli' || PHP_SAPI == 'phpdbg') { + print("Trace: "); + $t = array_reverse($e->getTrace()); + foreach($t as $n => $f) { + $c = $f['class'] ?? ''; + $t = $f['type'] ?? ''; + $a = implode(", ", array_map("stringer", $f['args'])); + print("$n: {$f['file']}({$f['line']}): {$c}{$t}{$f['function']}({$a})\n"); + } + + print("Message: $message\n"); + + if(isset($e->query)) { + print("Query: {$e->query}\n"); + } + + $phpver = phpversion(); + print("Version: $version (on $phpver)\n"); + } + else { + $q = (!isset($e->query) || is_null($e->query)) ? "" : "

Query: " . html_escape($e->query); + header("HTTP/1.0 500 Internal Error"); + echo ' Internal error - SCore-'.$version.' @@ -539,6 +559,7 @@ function _fatal_error(Exception $e): void '; + } } /**