nodejs/node · error · FilterArgumentError
method must be common, ceil or floor
Error message
method must be common, ceil or floor
What it means
The round filter rounds a number to a given precision using one of three strategies: 'common' (Python's round), 'ceil', or 'floor' (via math.ceil/math.floor). Any other method name is invalid because there is no corresponding rounding function to dispatch to.
Source
Thrown at tools/inspector_protocol/jinja2/filters.py:795
If you don't specify a method ``'common'`` is used.
.. sourcecode:: jinja
{{ 42.55|round }}
-> 43.0
{{ 42.55|round(1, 'floor') }}
-> 42.5
Note that even if rounded to 0 precision, a float is returned. If
you need a real integer, pipe it through `int`:
.. sourcecode:: jinja
{{ 42.55|round|int }}
-> 43
"""
if not method in ('common', 'ceil', 'floor'):
raise FilterArgumentError('method must be common, ceil or floor')
if method == 'common':
return round(value, precision)
func = getattr(math, method)
return func(value * (10 ** precision)) / (10 ** precision)
# Use a regular tuple repr here. This is what we did in the past and we
# really want to hide this custom type as much as possible. In particular
# we do not want to accidentally expose an auto generated repr in case
# people start to print this out in comments or something similar for
# debugging.
_GroupTuple = namedtuple('_GroupTuple', ['grouper', 'list'])
_GroupTuple.__repr__ = tuple.__repr__
_GroupTuple.__str__ = tuple.__str__
@environmentfilter
def do_groupby(environment, value, attribute):
"""Group a sequence of objects by a common attribute.View on GitHub (pinned to 1b2de5e052)
Solutions
- Use one of: 'common', 'ceil', or 'floor' (these are the only supported methods).
- For truncation use {{ value|round(0, 'floor')|int }} or multiply/integer-divide manually.
- Compute rounding in Python and pass the result to the template if you need a non-supported mode.
Example fix
{# before #}
{{ 4.7|round(0, 'up') }}
{# after #}
{{ 4.7|round(0, 'ceil') }} Defensive patterns
Strategy: validation
Validate before calling
import math
ALLOWED = ('common', 'ceil', 'floor')
if method not in ALLOWED:
raise ValueError('round method must be one of %r' % (ALLOWED,)) Type guard
def is_round_method(value: str) -> bool:
return value in ('common', 'ceil', 'floor') Try / catch
from jinja2.exceptions import FilterArgumentError
try:
out = env.call_filter('round', value, args=(precision, method))
except FilterArgumentError:
out = env.call_filter('round', value, args=(precision, 'common')) Prevention
- Document the three supported methods anywhere round is exposed.
- Restrict the method input to a fixed dropdown in any UI that drives it.
When it happens
Trigger: Calling {{ value|round(precision, method) }} with method not in ('common','ceil','floor') — e.g. {{ 4.2|round(1, 'up') }} or {{ x|round(0, 'nearest') }}.
Common situations: Assuming round supports arbitrary rounding modes (banker's, half-up, truncate); passing a locale-translated method name.
Related errors
- You can only sort by either "key" or "value"
- can't handle positional and keyword arguments at the same ti
- Unexpected keyword argument %r
- map requires a filter argument
- Missing parameter for attribute name
AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13).
Data as JSON: /api/errors/10abdf96c359b9a4.
Report an issue: GitHub.