twigphp/Twig · error · Twig\Error\RuntimeError

The list type " " does not exist, known types are: " ".

Error message

The list type "%s" does not exist, known types are: "%s".

What it means

createListFormatter validates the $type argument (the list connection type, e.g. 'and'/'or') against IntlExtension::availableListTypes(). An unknown type throws this RuntimeError listing the supported list types.

Solutions

  1. Use only types listed in the error (keys of availableListTypes(), typically 'and' and 'or')
  2. Fix the type string in the template or PHP call
  3. Validate config/input list types against availableListTypes() before rendering
  4. Default to 'and' when the configured type is unknown

Example fix

// before
{{ items|format_list(type='but') }}
// after
{{ items|format_list(type='and') }}
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

function isKnownListType(string $t): bool { return isset(IntlExtension::availableListTypes()[$t]); }

Try / catch

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

Prevention

When it happens

Trigger: Calling the format_list filter (formatList -> createListFormatter) with a type argument not in availableListTypes() — e.g. 'nor', 'but', or a typo like 'adn' instead of 'and'.

Common situations: Assuming arbitrary conjunctions are supported; typos in template arguments; user-supplied list type values passed straight through from config or request input.

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/f01dc30a83fa22b9. Report an issue: GitHub.

Appendix: source

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

        }

        foreach ($textAttrs as $name => $value) {
            $this->numberFormatters[$hash]->setTextAttribute(self::NUMBER_TEXT_ATTRIBUTES[$name], $value);
        }

        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])) {

View on GitHub (pinned to a414c3a491)