twigphp/Twig · error · Twig\Error\RuntimeError

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

Error message

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

What it means

formatNumber validates the $type argument against the list of types supported by NumberFormatter (default, decimal, currency, percent, scientific, spellout, ordinal, duration, etc.). This is a generic argument-validation guard: it fires whenever formatNumber is called with a $type string that is not one of these known type names, e.g. a typo like 'deciaml' or an unsupported style, so the error names the bad type and enumerates the valid alternatives.

Solutions

  1. Use one of the listed known types: default, int (integer), currency, percent, etc. as shown in the message.
  2. Fix typos in the type string.
  3. Whitelist/validate the type in config before passing.
  4. Use the style argument (decimal, percent, scientific...) rather than type for formatting styles.

Example fix

// before
format_number($n, type: 'float')
// after
format_number($n, type: 'default')
Defensive patterns

Strategy: validation

Validate before calling

$known = ['default','int','currency','percent']; if (!in_array($type, $known, true)) { $type = 'default'; }

Type guard

function isKnownNumberType(string $t): bool { return array_key_exists($t, \Symfony\Bridge\Twig\Extension\IntlExtension::NUMBER_TYPES ?? []); }

Try / catch

try { $s = format_number($n, type: $type); } catch (Twig\Error\RuntimeError $e) { $s = format_number($n); }

Prevention

When it happens

Trigger: Calling twig format_number(..., type: 'float') or format_number_style with a type string outside the allowed set, or a typo like 'decmial'.

Common situations: Copy-pasting style names into the type argument; user-configurable formatting options not whitelisted; upgrading and expecting a type that never existed.

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

Appendix: source

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

            return [];
        }
    }

    public function formatCurrency($amount, string $currency, array $attrs = [], ?string $locale = null): string
    {
        $formatter = $this->createNumberFormatter($locale, 'currency', $attrs);

        if (false === $ret = $formatter->formatCurrency($amount, $currency)) {
            throw new RuntimeError('Unable to format the given number as a currency.');
        }

        return $ret;
    }

    public function formatNumber($number, array $attrs = [], string $style = 'decimal', string $type = 'default', ?string $locale = null): string
    {
        if (!isset(self::NUMBER_TYPES[$type])) {
            throw new RuntimeError(\sprintf('The type "%s" does not exist, known types are: "%s".', $type, implode('", "', array_keys(self::NUMBER_TYPES))));
        }

        $formatter = $this->createNumberFormatter($locale, $style, $attrs);

        if (false === $ret = $formatter->format($number, self::NUMBER_TYPES[$type])) {
            throw new RuntimeError('Unable to format the given number.');
        }

        return $ret;
    }

    public function formatNumberStyle(string $style, $number, array $attrs = [], string $type = 'default', ?string $locale = null): string
    {
        return $this->formatNumber($number, $attrs, $style, $type, $locale);
    }

    /**
     * @param \DateTimeInterface|string|null  $date     A date or null to use the current time

View on GitHub (pinned to a414c3a491)