{"record":{"id":"4562a73727ab600c","repo":"Hmbown/CodeWhale","slug":"unit-must-be-chars-or-lines","errorCode":null,"errorMessage":"unit must be 'chars' or 'lines'","messagePattern":"unit must be 'chars' or 'lines'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"crates/tui/src/repl/runtime.rs","lineNumber":865,"sourceCode":"\ndef _slice_chars(start, end):\n    total = len(_context)\n    s = max(0, int(start))\n    e = max(s, min(total, int(end)))\n    return _context[s:e]\n\ndef _slice_lines(start, end):\n    lines = _context.splitlines()\n    s = max(0, int(start))\n    e = max(s, min(len(lines), int(end)))\n    return \"\\n\".join(lines[s:e])\n\ndef peek(start, end, unit=\"chars\"):\n    \"\"\"Return a bounded slice of the input by char offsets or line numbers.\"\"\"\n    if str(unit).lower() in (\"line\", \"lines\"):\n        return _slice_lines(start, end)\n    if str(unit).lower() not in (\"char\", \"chars\"):\n        raise ValueError(\"unit must be 'chars' or 'lines'\")\n    return _slice_chars(start, end)\n\ndef search(pattern, max_hits=100):\n    \"\"\"Regex-search the input and return bounded hit records with snippets.\"\"\"\n    max_hits = max(0, int(max_hits))\n    hits = []\n    if max_hits == 0:\n        return hits\n    rx = _re.compile(str(pattern), _re.MULTILINE)\n    for i, m in enumerate(rx.finditer(_context)):\n        if i >= max_hits:\n            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,","sourceCodeStart":847,"sourceCodeEnd":883,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/repl/runtime.rs#L847-L883","documentation":"peek() returns a bounded slice of the REPL input buffer either by character offsets or by line numbers. The unit parameter is normalized (case-insensitively) and must resolve to 'chars'/'char' or 'lines'/'line'; anything else is rejected with this ValueError. It is an eager fail-loud guard so a misspelled unit never silently falls back to a default slicing mode.","triggerScenarios":"Calling peek(start, end, unit=...) with a unit string other than chars/char/lines/line, e.g. unit=\"words\", unit=\"byte\", unit=None, unit=3, or a typo like unit=\"charr\".","commonSituations":"Hand-writing tool calls to the REPL peek helper and misspelling the unit; passing a non-string (int, None) unit from generated code; copying an example that used a different helper's unit vocabulary such as 'bytes' or 'words'.","solutions":["Pass unit=\"chars\" (default) or unit=\"lines\"","Fix typos in the unit string; matching is case-insensitive so 'Lines' is fine","Omit the unit argument entirely to get the default 'chars' behavior","If you need word- or byte-based slicing, implement it on top of peek's char slices"],"exampleFix":"// before\npeek(0, 500, unit=\"bytes\")\n// after\npeek(0, 500, unit=\"chars\")","handlingStrategy":"validation","validationCode":"const UNIT_OK = new Set([\"char\", \"chars\", \"line\", \"lines\"]);\nif (!UNIT_OK.has(String(unit).toLowerCase())) throw new Error(`unit must be 'chars' or 'lines', got ${unit}`);","typeGuard":"const isPeekUnit = (u) => typeof u === \"string\" && [\"char\",\"chars\",\"line\",\"lines\"].includes(u.toLowerCase());","tryCatchPattern":"try { const slice = peek(start, end, unit); } catch (e) { if (String(e).includes(\"unit must be\")) { /* retry with unit='chars' */ } else throw e; }","preventionTips":["Omit unit when char slicing is what you want — the default is 'chars'","Centralize allowed units in a constant/enum shared by all callers","Never pass raw user input as unit without normalizing"],"tags":["python","validation","argument-error"],"backgroundTag":"invalid-enum-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"}