Hmbown/CodeWhale · error · ValueError
max_chars must be > 0
Error message
max_chars must be > 0
What it means
chunk(max_chars=20000, overlap=0) in the embedded Python REPL coerces max_chars with int() and raises ValueError when it is 0 or negative. A positive window is what guarantees the chunk loop advances and keeps chunk counts bounded for large inputs. Note that int('abc') raises a different 'invalid literal' ValueError, so this exact message means the value was numeric but not positive.
Source
Thrown at crates/tui/src/repl/runtime.rs:895
break
start, end = m.span()
snippet_start = max(0, start - 120)
snippet_end = min(len(_context), end + 120)
hits.append({
"index": i,
"start": start,
"end": end,
"match": m.group(0),
"snippet": _context[snippet_start:snippet_end],
})
return hits
def chunk(max_chars=20000, overlap=0):
"""Return full-coverage input chunks with index/start/end/text fields."""
max_chars = int(max_chars)
overlap = max(0, int(overlap))
if max_chars <= 0:
raise ValueError("max_chars must be > 0")
if overlap >= max_chars:
raise ValueError("overlap must be smaller than max_chars")
chunks = []
start = 0
idx = 0
total = len(_context)
while start < total:
end = min(total, start + max_chars)
chunks.append({"index": idx, "start": start, "end": end, "text": _context[start:end]})
idx += 1
if end >= total:
break
start = end - overlap
return chunks
def chunk_context(max_chars=20000, overlap=0):
"""Compatibility alias for chunk()."""
return chunk(max_chars=max_chars, overlap=overlap)View on GitHub (pinned to 8880682c63)
Solutions
- Pass a positive window such as the 20000 default
- Clamp computed values: max_chars = max(1, int(computed))
- Skip chunking entirely for empty inputs; chunk returns [] anyway
Example fix
# before size = len(text) // 1_000_000 chunks = chunk(max_chars=size) # after chunks = chunk(max_chars=20000)
Defensive patterns
Strategy: validation
Validate before calling
window = int(computed_size)
if window <= 0:
window = 20000 # fall back to the documented default
chunks = chunk(max_chars=window) Try / catch
try:
chunks = chunk(max_chars=size)
except ValueError:
chunks = chunk() # defaults: max_chars=20000, overlap=0 Prevention
- Clamp computed window sizes with max(1, ...) at the source
- Never use 0 to mean 'default'; this API has no such convention
- Sanity-check derived sizes against the context length before chunking
When it happens
Trigger: Calling chunk(0), chunk(-1), chunk('0'), or passing a computed size that collapses to zero, e.g. max_chars = total // 10**9 or a ratio that rounds down to 0.
Common situations: Generated code deriving the window from a fraction of context length that underflows; passing 0 expecting 'use the default' semantics from other APIs; unit confusion between bytes, tokens, and chars.
Related errors
- overlap must be smaller than max_chars
- unit must be 'chars' or 'lines'
- version must be a semantic release identifier
- max_turns must be between 1 and 10000
- disabled_tools must use Codewhale catalog identifiers: ${",
AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16).
Data as JSON: /api/errors/10bf35e2a9ae80dd.
Report an issue: GitHub.