{"record":{"id":"ad1d5a0ca827c4fc","repo":"nodejs/node","slug":"buffer-size-too-small","errorCode":null,"errorMessage":"buffer size too small","messagePattern":"buffer size too small","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"tools/inspector_protocol/jinja2/environment.py","lineNumber":1262,"sourceCode":"\n        while 1:\n            try:\n                while c_size < size:\n                    c = next(self._gen)\n                    push(c)\n                    if c:\n                        c_size += 1\n            except StopIteration:\n                if not c_size:\n                    return\n            yield concat(buf)\n            del buf[:]\n            c_size = 0\n\n    def enable_buffering(self, size=5):\n        \"\"\"Enable buffering.  Buffer `size` items before yielding them.\"\"\"\n        if size <= 1:\n            raise ValueError('buffer size too small')\n\n        self.buffered = True\n        self._next = partial(next, self._buffered_generator(size))\n\n    def __iter__(self):\n        return self\n\n    def __next__(self):\n        return self._next()\n\n\n# hook in default template class.  if anyone reads this comment: ignore that\n# it's possible to use custom templates ;-)\nEnvironment.template_class = Template\n","sourceCodeStart":1244,"sourceCodeEnd":1277,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/inspector_protocol/jinja2/environment.py#L1244-L1277","documentation":"enable_buffering(size) on a Template turns on output buffering for the streaming generate() generator, concatenating `size` items before yielding each chunk. A size of 0 or 1 provides no buffering benefit and is rejected as a programming error.","triggerScenarios":"Calling template.enable_buffering(0), template.enable_buffering(1), or passing any value <= 1 (e.g. computed from a config that defaults to 1).","commonSituations":"Wiring enable_buffering to a tunable that defaults to 1; misreading the parameter as a byte size instead of an item count; trying to disable buffering by passing 1.","solutions":["Pass an integer >= 2, e.g. template.enable_buffering(5).","Validate the value before calling: if buffer_size > 1: tmpl.enable_buffering(buffer_size).","To disable buffering, set template.buffered = False instead of calling enable_buffering with a tiny size."],"exampleFix":"// before\ntmpl.enable_buffering(1)  # raises: buffer size too small\n\n// after\ntmpl.enable_buffering(5)\n# or to disable buffering:\ntmpl.buffered = False","handlingStrategy":"validation","validationCode":"def safe_enable_buffering(tmpl, size):\n    if not isinstance(size, int) or size <= 1:\n        raise ValueError('buffer size must be an integer >= 2, got %r' % (size,))\n    tmpl.enable_buffering(size)","typeGuard":"def is_valid_buffer_size(size) -> bool:\n    return isinstance(size, int) and size >= 2","tryCatchPattern":null,"preventionTips":["Treat the buffer size as a count of items, not bytes.","Bind the configured value with a minimum (e.g. max(2, cfg.buffer_size)).","To disable buffering set tmpl.buffered = False, never pass 1."],"tags":["jinja2","streaming","configuration","validation"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}