nodejs/node · error · RuntimeError
at least one item has to be provided
Error message
at least one item has to be provided
What it means
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.
Source
Thrown at tools/inspector_protocol/jinja2/utils.py:579
quote your attributes or HTML escape it in addition.
"""
if dumper is None:
dumper = json.dumps
rv = dumper(obj, **kwargs) \
.replace(u'<', u'\\u003c') \
.replace(u'>', u'\\u003e') \
.replace(u'&', u'\\u0026') \
.replace(u"'", u'\\u0027')
return Markup(rv)
@implements_iterator
class Cycler(object):
"""A cycle helper for templates."""
def __init__(self, *items):
if not items:
raise RuntimeError('at least one item has to be provided')
self.items = items
self.reset()
def reset(self):
"""Resets the cycle."""
self.pos = 0
@property
def current(self):
"""Returns the current item."""
return self.items[self.pos]
def next(self):
"""Goes one item ahead and returns it."""
rv = self.current
self.pos = (self.pos + 1) % len(self.items)
return rv
View on GitHub (pinned to 1b2de5e052)
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.
Example fix
// before
row_classes = config.get('row_classes', [])
c = Cycler(*row_classes)
// after
row_classes = config.get('row_classes') or ['default']
c = Cycler(*row_classes) Defensive patterns
Strategy: validation
Validate before calling
from jinja2.utils import Cycler items = source_list or ['default'] assert items, 'Cycler requires at least one item' c = Cycler(*items)
Type guard
def has_cycler_items(items) -> bool:
return len(items) > 0 Try / catch
# construction-time RuntimeError should be fixed at the call site,
# but if you must keep the process alive:
from jinja2.utils import Cycler
try:
c = Cycler(*items)
except RuntimeError:
c = Cycler('default') Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- no items for cycling given
- Tried to call non recursive loop. Maybe you forgot the 'rec
- Template module attribute is unavailable in async mode
- Loop length for some iterators cannot be lazily calculated i
- extended multiple times
AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13).
Data as JSON: /api/errors/0c1a4d965de9a7f5.
Report an issue: GitHub.