twigphp/Twig · error · Twig\Error\RuntimeError

The list width " " does not exist, known widths are: " ".

Error message

The list width "%s" does not exist, known widths are: "%s".

What it means

createListFormatter validates the $width argument (list width variant, e.g. 'wide'/'narrow') against IntlExtension::availableListWidths(). An unknown width throws this RuntimeError listing the supported widths.

Solutions

  1. Use only widths listed in the error (keys of availableListWidths(): 'wide', 'short', 'narrow')
  2. Fix the width string in the template or PHP call
  3. Validate configured widths against availableListWidths() before rendering
  4. Omit width to use the default 'wide'

Example fix

// before
{{ items|format_list(width='condensed') }}
// after
{{ items|format_list(width='narrow') }}
Defensive patterns

Strategy: validation

Validate before calling

if (!isset(IntlExtension::availableListWidths()[$width])) { throw new \InvalidArgumentException("Unknown list width $width"); }

Type guard

function isKnownListWidth(string $w): bool { return isset(IntlExtension::availableListWidths()[$w]); }

Try / catch

try { $out = $intl->formatList($strings, $type, $width); } catch (\Twig\Error\RuntimeError $e) { if (str_contains($e->getMessage(), 'list width')) { $out = $intl->formatList($strings, $type, 'wide'); } else { throw $e; } }

Prevention

When it happens

Trigger: Calling the format_list filter (formatList -> createListFormatter) with a width argument not in availableListWidths() — e.g. 'condensed', 'long', or a typo like 'wiede'.

Common situations: Typos in template arguments; assuming other ICU width names are supported; config- or user-supplied width values never validated against availableListWidths().

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of twigphp/Twig@a414c3a491 (2026-09-13). Data as JSON: /api/errors/74aca5e930cd3ddb. Report an issue: GitHub.

Appendix: source

Thrown at extra/intl-extra/IntlExtension.php:620

        foreach ($symbols as $name => $value) {
            $this->numberFormatters[$hash]->setSymbol(self::NUMBER_SYMBOLS[$name], $value);
        }

        return $this->numberFormatters[$hash];
    }

    private function createListFormatter(?string $locale, string $type, string $width): \IntlListFormatter
    {
        $listTypes = self::availableListTypes();

        if (!isset($listTypes[$type])) {
            throw new RuntimeError(\sprintf('The list type "%s" does not exist, known types are: "%s".', $type, implode('", "', array_keys($listTypes))));
        }

        $listWidths = self::availableListWidths();

        if (!isset($listWidths[$width])) {
            throw new RuntimeError(\sprintf('The list width "%s" does not exist, known widths are: "%s".', $width, implode('", "', array_keys($listWidths))));
        }

        if (null === $locale) {
            $locale = \Locale::getDefault();
        }

        $listTypeValue = $listTypes[$type];
        $listWidthValue = $listWidths[$width];

        $hash = $locale.'|'.$listTypeValue.'|'.$listWidthValue;

        if (!isset($this->listFormatters[$hash])) {
            if (\count($this->listFormatters) >= self::MAX_CACHED_FORMATTERS) {
                array_shift($this->listFormatters);
            }
            $this->listFormatters[$hash] = new \IntlListFormatter($locale, $listTypeValue, $listWidthValue);
        }

View on GitHub (pinned to a414c3a491)