From 486689ed317d92c628c7e377bdf84b1d55792c39 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Gomez Date: Mon, 18 Dec 2023 21:39:35 +0100 Subject: [PATCH] =?UTF-8?q?Mejorada=20la=20pantalla=20de=20error:=20ahora?= =?UTF-8?q?=20tambi=C3=A9n=20muestra=20si=20hay=20errores=20relacionados?= =?UTF-8?q?=20con=20la=20codificaci=C3=B3n=20de=20json.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/CrashReport.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Core/CrashReport.php b/Core/CrashReport.php index a4ac817596..9143838215 100644 --- a/Core/CrashReport.php +++ b/Core/CrashReport.php @@ -25,7 +25,7 @@ public static function getErrorInfo(int $code, string $message, string $file, in { // calculamos un hash para el error, de forma que en la web podamos dar respuesta automáticamente $errorUrl = parse_url($_SERVER["REQUEST_URI"] ?? '', PHP_URL_PATH); - $errorMessage = self::cleanErrorMessage($message); + $errorMessage = self::formatErrorMessage($message); $errorFile = str_replace(FS_FOLDER, '', $file); $errorHash = md5($code . $errorFile . $line . $errorMessage); $reportUrl = 'https://facturascripts.com/errores/' . $errorHash; @@ -148,7 +148,7 @@ public static function shutdown(): void $num = 1; $trace = explode("\n", $messageParts[1]); foreach (array_reverse($trace) as $value) { - if (trim($value) === 'thrown') { + if (trim($value) === 'thrown' || substr($value, 3) === '{main}') { continue; } @@ -156,6 +156,7 @@ public static function shutdown(): void $num++; } + echo '' . $num . '' . $info['file'] . ':' . $info['line'] . ''; echo ''; } @@ -200,9 +201,21 @@ public static function validateToken(string $token): bool return $token === self::newToken(); } - private static function cleanErrorMessage(string $message): string + private static function formatErrorMessage(string $message): string { - return str_replace([FS_FOLDER, 'Stack trace:'], ['', "\nStack trace:"], $message); + // quitamos el folder de las rutas + $message = str_replace(FS_FOLDER, '', $message); + + // partimos por la traza + $messageParts = explode("Stack trace:", $message); + + // si hay error de json, lo añadimos al mensaje + if (json_last_error()) { + $messageParts[0] .= "\n" . json_last_error_msg(); + } + + // ahora volvemos a unir el mensaje + return implode("\nStack trace:", $messageParts); } private static function trans(string $code): string