From 352e05d8e87dc2da9f920b3b1525d250909b37f2 Mon Sep 17 00:00:00 2001 From: ralf Date: Tue, 25 Oct 2022 14:31:10 +0200 Subject: [PATCH] catch exception in _try_lang to NOT generate a Fatal error by throwing another exception in the handler --- api/src/loader/exception.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/api/src/loader/exception.php b/api/src/loader/exception.php index 43750b6afd..65fc04186c 100755 --- a/api/src/loader/exception.php +++ b/api/src/loader/exception.php @@ -19,7 +19,7 @@ use EGroupware\Api; * This function is useful for exception handlers or early stages of the initialisation of the egw object, * as calling lang would try to load the translations, evtl. cause more errors, eg. because there's no db-connection. * - * @param string $key message in englich with %1, %2, ... placeholders + * @param string $key message in English with %1, %2, ... placeholders * @param string $vars =null multiple values to replace the placeholders * @return string translated message with placeholders replaced */ @@ -32,7 +32,16 @@ function try_lang($key,$vars=null) $vars = func_get_args(); array_shift($vars); // remove $key } - return class_exists('EGroupware\Api\Translation',false) ? Api\Translation::translate($key,$vars) : str_replace($varnames,$vars,$key); + if (class_exists('EGroupware\Api\Translation',false)) + { + try { + return Api\Translation::translate($key, $vars); + } + catch (\Throwable $e) { + // ignore + } + } + return str_replace($varnames,$vars,$key); } /** @@ -200,4 +209,4 @@ class egw_exception_warning extends Exception {} // install our error-handler only for catchable fatal errors and warnings // following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING -set_error_handler('egw_error_handler', E_RECOVERABLE_ERROR|E_USER_ERROR|E_WARNING|E_USER_WARNING); +set_error_handler('egw_error_handler', E_RECOVERABLE_ERROR|E_USER_ERROR|E_WARNING|E_USER_WARNING); \ No newline at end of file