{"record":{"id":"0c1a4d965de9a7f5","repo":"nodejs/node","slug":"at-least-one-item-has-to-be-provided","errorCode":null,"errorMessage":"at least one item has to be provided","messagePattern":"at least one item has to be provided","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"tools/inspector_protocol/jinja2/utils.py","lineNumber":579,"sourceCode":"    quote your attributes or HTML escape it in addition.\n    \"\"\"\n    if dumper is None:\n        dumper = json.dumps\n    rv = dumper(obj, **kwargs) \\\n        .replace(u'<', u'\\\\u003c') \\\n        .replace(u'>', u'\\\\u003e') \\\n        .replace(u'&', u'\\\\u0026') \\\n        .replace(u\"'\", u'\\\\u0027')\n    return Markup(rv)\n\n\n@implements_iterator\nclass Cycler(object):\n    \"\"\"A cycle helper for templates.\"\"\"\n\n    def __init__(self, *items):\n        if not items:\n            raise RuntimeError('at least one item has to be provided')\n        self.items = items\n        self.reset()\n\n    def reset(self):\n        \"\"\"Resets the cycle.\"\"\"\n        self.pos = 0\n\n    @property\n    def current(self):\n        \"\"\"Returns the current item.\"\"\"\n        return self.items[self.pos]\n\n    def next(self):\n        \"\"\"Goes one item ahead and returns it.\"\"\"\n        rv = self.current\n        self.pos = (self.pos + 1) % len(self.items)\n        return rv\n","sourceCodeStart":561,"sourceCodeEnd":597,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/inspector_protocol/jinja2/utils.py#L561-L597","documentation":"Raised by jinja2.utils.Cycler.__init__ when constructed with no items. Cycler is the standalone helper used by the {% cycle %} statement and by user code to alternate values; with zero items there is nothing to return from .current or pop, so the constructor refuses with RuntimeError.","triggerScenarios":"Calling Cycler() with no positional arguments in Python code. Instantiating Cycler(*classes) where classes is an empty list. Constructing a Cycler from a context variable that was not populated (e.g. Cycler(*theme_row_classes) with theme_row_classes unset).","commonSituations":"Theme/configuration-driven cycling where the configured list is empty in some environments. Generic helper that builds Cyclers from arbitrary iterables without a length check. Copy-paste from an example that assumed non-empty input.","solutions":["Supply at least one item: Cycler('a') or Cycler(*items or ['default']).","Validate the source list before construction: if not items: raise ValueError or fall back to a default.","In templates, prefer {% cycle 'default' %} with literal fallbacks when the data list may be empty.","Unit-test the helper with an empty input to fail fast at the right layer."],"exampleFix":"// before\nrow_classes = config.get('row_classes', [])\nc = Cycler(*row_classes)\n// after\nrow_classes = config.get('row_classes') or ['default']\nc = Cycler(*row_classes)","handlingStrategy":"validation","validationCode":"from jinja2.utils import Cycler\nitems = source_list or ['default']\nassert items, 'Cycler requires at least one item'\nc = Cycler(*items)","typeGuard":"def has_cycler_items(items) -> bool:\n    return len(items) > 0","tryCatchPattern":"# construction-time RuntimeError should be fixed at the call site,\n# but if you must keep the process alive:\nfrom jinja2.utils import Cycler\ntry:\n    c = Cycler(*items)\nexcept RuntimeError:\n    c = Cycler('default')","preventionTips":["Default cycle lists to a known value: items or ['default'].","Validate config-driven lists before constructing Cyclers.","Unit-test helpers that build Cyclers with empty input."],"tags":["jinja2","utils","cycler","runtime","template"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}