{"record":{"id":"0056a8f48134f6d1","repo":"twigphp/Twig","slug":"unable-to-format-the-given-list-s","errorCode":null,"errorMessage":"Unable to format the given list: %s","messagePattern":"Unable to format the given list: (.+?)","errorType":"exception","errorClass":"Twig\\Error\\RuntimeError","httpStatus":null,"severity":"error","filePath":"extra/intl-extra/IntlExtension.php","lineNumber":456,"sourceCode":"     * @param \\DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged\n     */\n    public function formatTime(Environment $env, $date, ?string $timeFormat = null, string $pattern = '', $timezone = null, ?string $calendar = null, ?string $locale = null): string\n    {\n        return $this->formatDateTime($env, $date, 'none', $timeFormat, $pattern, $timezone, $calendar, $locale);\n    }\n\n    /**\n     * @param array<string|\\Stringable> $strings A list of items to be joined into a formatted list\n     */\n    public function formatList(array $strings, string $type = 'and', string $width = 'wide', ?string $locale = null): string\n    {\n        if (!class_exists('IntlListFormatter')) {\n            throw new RuntimeError('The \"format_list\" filter requires the \"IntlListFormatter\" class, which is available since PHP 8.5.');\n        }\n\n        $formatter = $this->createListFormatter($locale, $type, $width);\n        if (false === $ret = $formatter->format($strings)) {\n            throw new RuntimeError(\\sprintf('Unable to format the given list: %s', $formatter->getErrorMessage()));\n        }\n\n        return $ret;\n    }\n\n    private function createDateFormatter(?string $locale, ?string $dateFormat, ?string $timeFormat, string $pattern, ?\\DateTimeZone $timezone, ?string $calendar): \\IntlDateFormatter\n    {\n        $dateFormats = self::availableDateFormats();\n\n        if (null !== $dateFormat && !isset($dateFormats[$dateFormat])) {\n            throw new RuntimeError(\\sprintf('The date format \"%s\" does not exist, known formats are: \"%s\".', $dateFormat, implode('\", \"', array_keys($dateFormats))));\n        }\n\n        if (null !== $timeFormat && !isset(self::TIME_FORMATS[$timeFormat])) {\n            throw new RuntimeError(\\sprintf('The time format \"%s\" does not exist, known formats are: \"%s\".', $timeFormat, implode('\", \"', array_keys(self::TIME_FORMATS))));\n        }\n\n        if (null === $locale) {","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/extra/intl-extra/IntlExtension.php#L438-L474","documentation":"After constructing an IntlListFormatter, formatList calls ->format($strings). IntlListFormatter signals failure by returning false, and its getErrorMessage() holds the reason (often an intl/ICU error such as U_MEMORY_ALLOCATION_ERROR or bad input). The extension surfaces that message wrapped in this RuntimeError.","triggerScenarios":"Calling IntlListFormatter::format() via the format_list filter and receiving false — e.g. intl/ICU internal failure reported by getErrorMessage(), or invalid underlying data the formatter cannot handle.","commonSituations":"Broken or misconfigured ICU library on the host; extremely large input lists exhausting memory; corrupted locale data causing the formatter to fail during formatting.","solutions":["Read the embedded message from formatter->getErrorMessage() in the exception text to identify the underlying ICU failure","Verify the host's ICU/intl installation is healthy (php -i intl section, matching ICU data)","Reduce the size of the input list or ensure all items are strings/stringable and non-recursive","Test the same format() call in a plain PHP script to rule out Twig-specific wrapping"],"exampleFix":"// before\ntry {\n    echo $twig->render('t.twig', ['items' => $hugeList]);\n} catch (\\Twig\\Error\\RuntimeError $e) {\n    // \"Unable to format the given list: ...\"\n}\n// after\n$items = \\count($hugeList) > 5000 ? \\array_slice($hugeList, 0, 5000) : $hugeList;\ntry {\n    echo $twig->render('t.twig', ['items' => $items]);\n} catch (\\Twig\\Error\\RuntimeError $e) {\n    error_log('format_list failed: '.$e->getMessage());\n    echo implode(', ', $items);\n}","handlingStrategy":"try-catch","validationCode":"if (!function_exists('intl_get_error_code') || intl_get_error_code() !== 0) { /* intl broken, avoid format_list */ }","typeGuard":null,"tryCatchPattern":"try { $out = $item->formatList($strings); } catch (\\Twig\\Error\\RuntimeError $e) { $out = implode(', ', $strings); }","preventionTips":["Keep ICU data current on the host","Cap list sizes before formatting","Log formatter->getErrorMessage() for diagnosis"],"tags":["php","intl","icu","formatting"],"backgroundTag":"unsupported-operation","analyzedSha":"a414c3a491defb5a60f2fc88ef79ff37c90010cd","analyzedAt":"2026-09-13T15:10:46.849Z","contentChangedAt":"2026-09-13T15:10:46.849Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}