{"record":{"id":"8a4a108baeadb43d","repo":"nodejs/node","slug":"map-requires-a-filter-argument","errorCode":null,"errorMessage":"map requires a filter argument","messagePattern":"map requires a filter argument","errorType":"exception","errorClass":"FilterArgumentError","httpStatus":null,"severity":"error","filePath":"tools/inspector_protocol/jinja2/filters.py","lineNumber":1096,"sourceCode":"    return htmlsafe_json_dumps(value, dumper=dumper, **options)\n\n\ndef prepare_map(args, kwargs):\n    context = args[0]\n    seq = args[1]\n\n    if len(args) == 2 and 'attribute' in kwargs:\n        attribute = kwargs.pop('attribute')\n        if kwargs:\n            raise FilterArgumentError('Unexpected keyword argument %r' %\n                next(iter(kwargs)))\n        func = make_attrgetter(context.environment, attribute)\n    else:\n        try:\n            name = args[2]\n            args = args[3:]\n        except LookupError:\n            raise FilterArgumentError('map requires a filter argument')\n        func = lambda item: context.environment.call_filter(\n            name, item, args, kwargs, context=context)\n\n    return seq, func\n\n\ndef prepare_select_or_reject(args, kwargs, modfunc, lookup_attr):\n    context = args[0]\n    seq = args[1]\n    if lookup_attr:\n        try:\n            attr = args[2]\n        except LookupError:\n            raise FilterArgumentError('Missing parameter for attribute name')\n        transfunc = make_attrgetter(context.environment, attr)\n        off = 1\n    else:\n        off = 0","sourceCodeStart":1078,"sourceCodeEnd":1114,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/inspector_protocol/jinja2/filters.py#L1078-L1114","documentation":"prepare_map requires the map filter to be told what to do: either an 'attribute' keyword or a positional filter name (args[2]). If neither is supplied (args has only context and seq, and no 'attribute' kwarg), the lookup for args[2] raises LookupError which Jinja2 converts to FilterArgumentError.","triggerScenarios":"Calling {{ seq|map }} with no argument at all, e.g. {{ items|map }}.","commonSituations":"Forgetting the attribute or filter argument; building the filter call dynamically and dropping the argument.","solutions":["Provide an attribute: {{ users|map(attribute='email') }}.","Or provide a filter name: {{ items|map('upper') }} or {{ items|map('round', 2) }}."],"exampleFix":"{# before #}\n{{ items|map }}\n\n{# after #}\n{{ items|map('upper') }}","handlingStrategy":"validation","validationCode":"def require_map_argument(attribute=None, filter_name=None, args=()):\n    if attribute is None and filter_name is None:\n        raise ValueError('map requires an attribute or a filter name')\n    return {'attribute': attribute} if attribute else (filter_name,) + tuple(args)","typeGuard":"def map_has_argument(attribute, filter_name) -> bool:\n    return attribute is not None or filter_name is not None","tryCatchPattern":"from jinja2.exceptions import FilterArgumentError\ntry:\n    out = env.call_filter('map', seq, args=(name,))\nexcept FilterArgumentError:\n    out = seq  # or apply a sensible default filter","preventionTips":["Always pass either attribute= or a filter name to map.","Add a template lint rule that flags bare |map."],"tags":["jinja2","filter","map","validation"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}