Issue Bug Closed

#107008503 error in backend reports due to missing error parameter; PHP-dependent return value of sprintf

Thorsten Born 07/01/25, 07:55 updated 12/02/25, 14:37

Description

Hello!

Since the update to 12.4.33 the PHP file LabelBag exists, which is used for the reports in the TYPO3 backend (perhaps also for other functions).
Under certain circumstances (special PHP version/settings?) an error is generated here:

Uncaught TYPO3 Exception: 4 arguments are required, 3 given | ArgumentCountError thrown in file vendor/typo3/cms-core/Classes/Localization/LabelBag.php in line 48.

We were only able to reproduce the error on one instance, PHP version 8.1.2-1ubuntu2.21 – the error does not occur with PHP 8.1 under ddev.
The error is triggered by a label (here in German):

Mime-Typ "%s" für Dateierweiterung "%s" nicht zulässig (erwartet: %s)

With the error parameters:

[0] => application/octet-stream
[1] => mp3

The error messages or the transferred parameters would therefore have to be adapted.

To avoid the 503, the LabelBag.php can be changed as follows (here as a patch, as we use it now):

diff --git a/vendor/typo3/cms-core/Classes/Localization/LabelBag.php b/vendor/typo3/cms-core/Classes/Localization/LabelBag.php
--- a/vendor/typo3/cms-core/Classes/Localization/LabelBag.php
+++ b/vendor/typo3/cms-core/Classes/Localization/LabelBag.php
@@ -44,14 +44,23 @@
     public function compile(LanguageService $languageService): string
     {
         $label = $languageService->sL($this->key);
-        return sprintf(
-            $label,
-            ...$this->arguments
-        ) ?: sprintf(
-            'Error: could not translate key "%s" with value "%s" and %d argument(s)!',
-            $this->key,
-            $label,
-            count($this->arguments)
-        );
+        try {
+            $result = sprintf($label, ...$this->arguments);
+
+            return $result ?: sprintf(
+                'Error: could not translate key "%s" with value "%s" and %d argument(s)!',
+                $this->key,
+                $label,
+                count($this->arguments)
+            );
+        } catch (\ArgumentCountError | \ValueError $e) {
+            return sprintf(
+                'Error: could not translate key "%s" with value "%s" and %d argument(s)! (Exception: %s)',
+                $this->key,
+                $label,
+                count($this->arguments),
+                $e->getMessage()
+            );
+        }
     }
 }

Reviews 5