{"record":{"id":"cb251db2ae4a935f","repo":"tirth8205/code-review-graph","slug":"empty-json-document","errorCode":null,"errorMessage":"empty JSON document","messagePattern":"empty JSON document","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"code_review_graph/uninstall.py","lineNumber":315,"sourceCode":"        raise ValueError(\"expected JSON array\")\n    elements: list[_Element] = []\n    cursor = index + 1\n    while cursor < len(tokens) and tokens[cursor].kind != \"]\":\n        if tokens[cursor].kind == \",\":  # trailing comma\n            cursor += 1\n            continue\n        value_end = _skip_value(tokens, cursor)\n        comma_index = value_end if (\n            value_end < len(tokens) and tokens[value_end].kind == \",\"\n        ) else None\n        elements.append(_Element(cursor, value_end, comma_index))\n        cursor = value_end + 1 if comma_index is not None else value_end\n    return elements\n\n\ndef _find_value(tokens: Sequence[_Token], path: Sequence[str | int]) -> int:\n    if not tokens:\n        raise ValueError(\"empty JSON document\")\n    current = 0\n    for component in path:\n        if isinstance(component, str):\n            member = next(\n                (item for item in _object_members(tokens, current) if item.key == component),\n                None,\n            )\n            if member is None:\n                raise KeyError(component)\n            current = member.value_index\n        else:\n            elements = _array_elements(tokens, current)\n            if component < 0 or component >= len(elements):\n                raise IndexError(component)\n            current = elements[component].value_index\n    return current\n\n","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/tirth8205/code-review-graph/blob/b58668751ab0c7670c078cf7cbd4d1f5b8e54f81/code_review_graph/uninstall.py#L297-L333","documentation":"Raised by _find_value when the token list produced by the JSONC tokenizer is empty — there is no JSON content at all to search. The removal machinery refuses to operate on a document with zero tokens, since there is nothing to locate or delete.","triggerScenarios":"Calling the removal API on an empty string, a file containing only whitespace, or a file consisting solely of comments (which the tokenizer strips). Also possible if the wrong file path was read (empty/blank content).","commonSituations":"Config file was emptied by a previous failed uninstall or manual cleanup; file contains only a comment header; code read the wrong path (missing file handled elsewhere, blank file not); race where another process truncated the file.","solutions":["Check the file content is non-empty and contains actual JSON before invoking removal","If only comments remain, treat the file as already-cleaned and skip removal (optionally delete the file if that's the uninstall policy)","Verify the correct file path is being read","Guard with a token/parse pre-check and treat empty documents as a no-op"],"exampleFix":"# before\n_remove_jsonc_paths(\"\" , [(\"key\",)])  # -> ValueError: empty JSON document\n\n# after\nif not text.strip():\n    return  # nothing to remove\n_remove_jsonc_paths(text, [(\"key\",)])","handlingStrategy":"type-guard","validationCode":"def has_json_content(text: str) -> bool:\n    import re\n    stripped = re.sub(r\"//[^\\n]*|/\\*.*?\\*/\", \"\", text, flags=re.S).strip()\n    return len(stripped) > 0","typeGuard":"def is_editable_jsonc(text: str) -> bool:\n    import re\n    return bool(re.sub(r\"//[^\\n]*|/\\*.*?\\*/\", \"\", text, flags=re.S).strip())","tryCatchPattern":"try:\n    _remove_jsonc_paths(text, paths)\nexcept ValueError as e:\n    if 'empty JSON document' in str(e):\n        return  # nothing to do","preventionTips":["Skip blank/comment-only files before calling removal","Treat empty config as already-uninstalled","Verify the file path and read result before editing"],"tags":["json","jsonc","empty-file","uninstall","tokenizer"],"backgroundTag":"empty-json-input","analyzedSha":"b58668751ab0c7670c078cf7cbd4d1f5b8e54f81","analyzedAt":"2026-08-28T13:19:08.966Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}