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

History 512

  1. Garvin Hicking commented and changed status New Accepted priority Should have Must have Is Regression 1 <span data-processor="relativetime" data-value="2025-07-01T08:23:08+00:00" > 07/01/25, 08:23 </span>

    I’m sorry, I caused this by introducing a new placeholder argument to the message, when a new label identifcator would have needed to be created instead. Because now the translation servers already deliver the new language file with the updated parameter, but the Code of the TYPO3 instance does not recognize it. There has been no release made yet with the PHP relevant changes needed for it to work.

    I’ll see how to remedy this by introducing a new key and fixing the current translation.

    For now you could edit the german localization XLF file (core/Resources/Private/Language/de.fileMessages.xlf) and change

          <trans-unit id="FileUtility.MimeTypeNotAllowedForFileExtension" approved="yes">
            <source>Mime-type "%s" not allowed for file extension "%s".</source>
            <target state="final">Mime-Typ "%s" für Dateierweiterung "%s" nicht zulässig.</target>
          </trans-unit>
  2. Gerrit Code Review pushed patch set 1 for main to change 89952 status Accepted Under Review <span data-processor="relativetime" data-value="2025-07-01T08:31:19+00:00" > 07/01/25, 08:31 </span>

  3. Garvin Hicking commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2025-07-01T17:50:09+00:00" > 07/01/25, 17:50 </span>

    Applied in changeset commit:2727a6d2af5df187aa0a992eac2f1b848a7c368b.