twigphp/Twig · error · Twig\Error\RuntimeError
Unable to format the given list
Error message
Unable to format the given list: %s
What it means
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.
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
Example fix
// before
try {
echo $twig->render('t.twig', ['items' => $hugeList]);
} catch (\Twig\Error\RuntimeError $e) {
// "Unable to format the given list: ..."
}
// after
$items = \count($hugeList) > 5000 ? \array_slice($hugeList, 0, 5000) : $hugeList;
try {
echo $twig->render('t.twig', ['items' => $items]);
} catch (\Twig\Error\RuntimeError $e) {
error_log('format_list failed: '.$e->getMessage());
echo implode(', ', $items);
} Defensive patterns
Strategy: try-catch
Validate before calling
if (!function_exists('intl_get_error_code') || intl_get_error_code() !== 0) { /* intl broken, avoid format_list */ } Try / catch
try { $out = $item->formatList($strings); } catch (\Twig\Error\RuntimeError $e) { $out = implode(', ', $strings); } Prevention
- Keep ICU data current on the host
- Cap list sizes before formatting
- Log formatter->getErrorMessage() for diagnosis
When it happens
Trigger: 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.
Common situations: Broken or misconfigured ICU library on the host; extremely large input lists exhausting memory; corrupted locale data causing the formatter to fail during formatting.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- The "format_list" filter requires the "IntlListFormatter"…
- The date format " " does not exist, known formats are: " ".
- The time format " " does not exist, known formats are: " ".
- The style " " does not exist, known styles are: " ".
- The number formatter attribute
AI-assisted analysis of twigphp/Twig@a414c3a491 (2026-09-13).
Data as JSON: /api/errors/0056a8f48134f6d1.
Report an issue: GitHub.
Appendix: source
Thrown at extra/intl-extra/IntlExtension.php:456
* @param \DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged
*/
public function formatTime(Environment $env, $date, ?string $timeFormat = null, string $pattern = '', $timezone = null, ?string $calendar = null, ?string $locale = null): string
{
return $this->formatDateTime($env, $date, 'none', $timeFormat, $pattern, $timezone, $calendar, $locale);
}
/**
* @param array<string|\Stringable> $strings A list of items to be joined into a formatted list
*/
public function formatList(array $strings, string $type = 'and', string $width = 'wide', ?string $locale = null): string
{
if (!class_exists('IntlListFormatter')) {
throw new RuntimeError('The "format_list" filter requires the "IntlListFormatter" class, which is available since PHP 8.5.');
}
$formatter = $this->createListFormatter($locale, $type, $width);
if (false === $ret = $formatter->format($strings)) {
throw new RuntimeError(\sprintf('Unable to format the given list: %s', $formatter->getErrorMessage()));
}
return $ret;
}
private function createDateFormatter(?string $locale, ?string $dateFormat, ?string $timeFormat, string $pattern, ?\DateTimeZone $timezone, ?string $calendar): \IntlDateFormatter
{
$dateFormats = self::availableDateFormats();
if (null !== $dateFormat && !isset($dateFormats[$dateFormat])) {
throw new RuntimeError(\sprintf('The date format "%s" does not exist, known formats are: "%s".', $dateFormat, implode('", "', array_keys($dateFormats))));
}
if (null !== $timeFormat && !isset(self::TIME_FORMATS[$timeFormat])) {
throw new RuntimeError(\sprintf('The time format "%s" does not exist, known formats are: "%s".', $timeFormat, implode('", "', array_keys(self::TIME_FORMATS))));
}
if (null === $locale) {View on GitHub (pinned to a414c3a491)