nodejs/node · error · FilterArgumentError

can't handle positional and keyword arguments at the same ti

Error message

can't handle positional and keyword arguments at the same time

What it means

The format filter (do_format) mirrors Python's % operator via soft_unicode(value) % (kwargs or args). Python string interpolation cannot mix positional and keyword conversion specifiers in a single % call against a single tuple/dict, so Jinja2 rejects the combination up front with FilterArgumentError.

Source

Thrown at tools/inspector_protocol/jinja2/filters.py:683

    override this default using the first parameter.
    """
    try:
        return float(value)
    except (TypeError, ValueError):
        return default


def do_format(value, *args, **kwargs):
    """
    Apply python string formatting on an object:

    .. sourcecode:: jinja

        {{ "%s - %s"|format("Hello?", "Foo!") }}
            -> Hello? - Foo!
    """
    if args and kwargs:
        raise FilterArgumentError('can\'t handle positional and keyword '
                                  'arguments at the same time')
    return soft_unicode(value) % (kwargs or args)


def do_trim(value):
    """Strip leading and trailing whitespace."""
    return soft_unicode(value).strip()


def do_striptags(value):
    """Strip SGML/XML tags and replace adjacent whitespace by one space.
    """
    if hasattr(value, '__html__'):
        value = value.__html__()
    return Markup(text_type(value)).striptags()


def do_slice(value, slices, fill_with=None):

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Use only positional arguments: {{ '%s %s'|format('a', 'b') }}.
  2. Or use only keyword arguments: {{ '%(x)s %(y)s'|format(x='a', y='b') }}.
  3. Split into two format calls if you truly need both styles.

Example fix

{# before #}
{{ '%s %(x)s'|format('a', x='b') }}

{# after #}
{{ '%s %s'|format('a', 'b') }}
Defensive patterns

Strategy: validation

Validate before calling

def safe_format(tmpl, *args, **kwargs):
    if args and kwargs:
        raise ValueError('format: pass only positional OR only keyword args')
    return tmpl % (kwargs or args)

Type guard

def format_args_consistent(args, kwargs) -> bool:
    return not (args and kwargs)

Try / catch

from jinja2.exceptions import FilterArgumentError
try:
    out = env.call_filter('format', value, args=args, kwargs=kwargs)
except FilterArgumentError:
    # fall back to whichever side is non-empty
    only = kwargs or args
    out = env.call_filter('format', value, args=only if isinstance(only, tuple) else (),
                          kwargs=only if isinstance(only, dict) else {})

Prevention

When it happens

Trigger: Calling {{ tmpl|format(a, b, x=c) }} (both positional *args and keyword **kwargs non-empty) — e.g. {{ '%s %(x)s'|format('a', x='b') }}.

Common situations: Trying to combine '%s' style with '%(name)s' style placeholders in one format string and supplying both arg kinds.

Related errors


AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13). Data as JSON: /api/errors/226c52b4e3de698b. Report an issue: GitHub.