{"record":{"id":"cc10096471918657","repo":"twigphp/Twig","slug":"the-number-formatter-rounding-mode-s-does-not-exist-known","errorCode":null,"errorMessage":"The number formatter rounding mode \"%s\" does not exist, known modes are: \"%s\".","messagePattern":"The number formatter rounding mode \"(.+?)\" does not exist, known modes are: \"(.+?)\"\\.","errorType":"exception","errorClass":"Twig\\Error\\RuntimeError","httpStatus":null,"severity":"error","filePath":"extra/intl-extra/IntlExtension.php","lineNumber":583,"sourceCode":"\n        ksort($attrs);\n        $hash = $locale.'|'.$style.'|'.json_encode($attrs).'|'.json_encode($textAttrs).'|'.json_encode($symbols);\n\n        if (!isset($this->numberFormatters[$hash])) {\n            if (\\count($this->numberFormatters) >= self::MAX_CACHED_FORMATTERS) {\n                array_shift($this->numberFormatters);\n            }\n            $this->numberFormatters[$hash] = new \\NumberFormatter($locale, self::NUMBER_STYLES[$style]);\n        }\n\n        foreach ($attrs as $name => $value) {\n            if (!isset(self::NUMBER_ATTRIBUTES[$name])) {\n                throw new RuntimeError(\\sprintf('The number formatter attribute \"%s\" does not exist, known attributes are: \"%s\".', $name, implode('\", \"', array_keys(self::NUMBER_ATTRIBUTES))));\n            }\n\n            if ('rounding_mode' === $name) {\n                if (!isset(self::NUMBER_ROUNDING_ATTRIBUTES[$value])) {\n                    throw new RuntimeError(\\sprintf('The number formatter rounding mode \"%s\" does not exist, known modes are: \"%s\".', $value, implode('\", \"', array_keys(self::NUMBER_ROUNDING_ATTRIBUTES))));\n                }\n\n                $value = self::NUMBER_ROUNDING_ATTRIBUTES[$value];\n            } elseif ('padding_position' === $name) {\n                if (!isset(self::NUMBER_PADDING_ATTRIBUTES[$value])) {\n                    throw new RuntimeError(\\sprintf('The number formatter padding position \"%s\" does not exist, known positions are: \"%s\".', $value, implode('\", \"', array_keys(self::NUMBER_PADDING_ATTRIBUTES))));\n                }\n\n                $value = self::NUMBER_PADDING_ATTRIBUTES[$value];\n            }\n\n            $this->numberFormatters[$hash]->setAttribute(self::NUMBER_ATTRIBUTES[$name], $value);\n        }\n\n        foreach ($textAttrs as $name => $value) {\n            $this->numberFormatters[$hash]->setTextAttribute(self::NUMBER_TEXT_ATTRIBUTES[$name], $value);\n        }\n","sourceCodeStart":565,"sourceCodeEnd":601,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/extra/intl-extra/IntlExtension.php#L565-L601","documentation":"When the attribute 'rounding_mode' is set in $attrs, its value is validated against IntlExtension::NUMBER_ROUNDING_ATTRIBUTES. A value that is not a known rounding mode name throws this RuntimeError listing the valid modes.","triggerScenarios":"Calling format_number/format_currency with attrs={'rounding_mode': X} where X is not a key of NUMBER_ROUNDING_ATTRIBUTES — e.g. 'half_up' misspelled as 'halfup', or a raw constant name like 'ROUND_HALFUP'.","commonSituations":"Using \\NumberFormatter::ROUND_* constant names verbatim as strings; typos in template arguments; config-driven rounding modes not validated.","solutions":["Use one of the modes listed in the error (keys of NUMBER_ROUNDING_ATTRIBUTES, e.g. 'half_up', 'half_even', 'floor', 'ceiling')","Fix the rounding mode string in the attrs array","Validate configured rounding modes against NUMBER_ROUNDING_ATTRIBUTES keys","Omit rounding_mode to keep the locale default"],"exampleFix":"// before\n{{ n|format_number(attrs={'rounding_mode': 'ROUND_HALF_UP'}) }}\n// after\n{{ n|format_number(attrs={'rounding_mode': 'half_up'}) }}","handlingStrategy":"validation","validationCode":"if (isset($attrs['rounding_mode']) && !isset(IntlExtension::NUMBER_ROUNDING_ATTRIBUTES[$attrs['rounding_mode']])) { throw new \\InvalidArgumentException('Unknown rounding mode'); }","typeGuard":"function isKnownRoundingMode(string $m): bool { return isset(IntlExtension::NUMBER_ROUNDING_ATTRIBUTES[$m]); }","tryCatchPattern":"try { $out = $intl->formatNumber($n, $style, $attrs); } catch (\\Twig\\Error\\RuntimeError $e) { if (str_contains($e->getMessage(), 'rounding mode')) { unset($attrs['rounding_mode']); $out = $intl->formatNumber($n, $style, $attrs); } else { throw $e; } }","preventionTips":["Use the documented rounding mode strings only","Normalize config values through a mapping table","Test each rounding mode key in CI"],"tags":["php","intl","number-formatting","rounding"],"backgroundTag":"invalid-enum-value","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"}