{"record":{"id":"10bf35e2a9ae80dd","repo":"Hmbown/CodeWhale","slug":"max-chars-must-be-0","errorCode":null,"errorMessage":"max_chars must be > 0","messagePattern":"max_chars must be > 0","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"crates/tui/src/repl/runtime.rs","lineNumber":895,"sourceCode":"            break\n        start, end = m.span()\n        snippet_start = max(0, start - 120)\n        snippet_end = min(len(_context), end + 120)\n        hits.append({\n            \"index\": i,\n            \"start\": start,\n            \"end\": end,\n            \"match\": m.group(0),\n            \"snippet\": _context[snippet_start:snippet_end],\n        })\n    return hits\n\ndef chunk(max_chars=20000, overlap=0):\n    \"\"\"Return full-coverage input chunks with index/start/end/text fields.\"\"\"\n    max_chars = int(max_chars)\n    overlap = max(0, int(overlap))\n    if max_chars <= 0:\n        raise ValueError(\"max_chars must be > 0\")\n    if overlap >= max_chars:\n        raise ValueError(\"overlap must be smaller than max_chars\")\n    chunks = []\n    start = 0\n    idx = 0\n    total = len(_context)\n    while start < total:\n        end = min(total, start + max_chars)\n        chunks.append({\"index\": idx, \"start\": start, \"end\": end, \"text\": _context[start:end]})\n        idx += 1\n        if end >= total:\n            break\n        start = end - overlap\n    return chunks\n\ndef chunk_context(max_chars=20000, overlap=0):\n    \"\"\"Compatibility alias for chunk().\"\"\"\n    return chunk(max_chars=max_chars, overlap=overlap)","sourceCodeStart":877,"sourceCodeEnd":913,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/repl/runtime.rs#L877-L913","documentation":"chunk() splits the REPL input into full-coverage slices of at most max_chars characters. A non-positive max_chars would produce an infinite/empty chunking loop, so the function rejects max_chars <= 0 with this ValueError before doing any work.","triggerScenarios":"Calling chunk(max_chars=0), a negative max_chars, or a value that int() coerces to <= 0 (e.g. max_chars=\"0\", max_chars=None raising earlier, max_chars=-500).","commonSituations":"Computing max_chars from a config or CLI flag that defaulted to 0; an off-by-sign bug when deriving the budget from a remaining-token count; passing an empty string that int() coerces unexpectedly in generated calls.","solutions":["Pass a positive integer, e.g. chunk(max_chars=20000)","Validate the source config/flag before calling and clamp with max(1, value)","If deriving dynamically, ensure the computed budget is positive before the call"],"exampleFix":"// before\nchunk(max_chars=0)\n// after\nchunk(max_chars=20000)","handlingStrategy":"validation","validationCode":"const mc = Math.trunc(Number(maxChars));\nif (!Number.isFinite(mc) || mc <= 0) throw new Error(\"max_chars must be > 0 before calling chunk()\");","typeGuard":"const isPositiveInt = (v) => Number.isInteger(v) && v > 0;","tryCatchPattern":"try { const chunks = chunk(maxChars, overlap); } catch (e) { if (String(e).includes(\"max_chars must be\")) { return chunk(20000, overlap); } throw e; }","preventionTips":["Clamp derived budgets with Math.max(1, value) before calling","Validate config fields that feed max_chars at load time","Never pass 0 as a 'use default' sentinel — omit the argument instead"],"tags":["python","validation","argument-error"],"backgroundTag":"invalid-argument-value","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}