{"record":{"id":"d554837600198820","repo":"tirth8205/code-review-graph","slug":"expected-json-array","errorCode":null,"errorMessage":"expected JSON array","messagePattern":"expected JSON array","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"code_review_graph/uninstall.py","lineNumber":297,"sourceCode":"        if key_token.kind != \"string\" or not isinstance(key_token.value, str):\n            raise ValueError(\"expected JSON object key\")\n        if cursor + 1 >= len(tokens) or tokens[cursor + 1].kind != \":\":\n            raise ValueError(\"expected colon after JSON object key\")\n        value_index = cursor + 2\n        value_end = _skip_value(tokens, value_index)\n        comma_index = value_end if (\n            value_end < len(tokens) and tokens[value_end].kind == \",\"\n        ) else None\n        members.append(\n            _Member(key_token.value, cursor, value_index, value_end, comma_index)\n        )\n        cursor = value_end + 1 if comma_index is not None else value_end\n    return members\n\n\ndef _array_elements(tokens: Sequence[_Token], index: int) -> list[_Element]:\n    if index >= len(tokens) or tokens[index].kind != \"[\":\n        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\")","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/tirth8205/code-review-graph/blob/b58668751ab0c7670c078cf7cbd4d1f5b8e54f81/code_review_graph/uninstall.py#L279-L315","documentation":"Raised by _array_elements when the token at the given index is not the '[' that opens a JSON array (or the index is past the token stream end). The path being edited assumed an array at that position, but the document has a different token there. Companion to 'expected JSON object' for the array case.","triggerScenarios":"Removing an indexed path element (e.g. path [..., 0]) whose parent resolves to an object, string, or number instead of an array; malformed/truncated JSONC where the '[' is missing; using an int component against a key-value container.","commonSituations":"Path built with numeric indices for what is actually an object of named keys (e.g. tools stored as {\"name\": {...}} not [...]); config format changed between versions from array to object; hand-edit broke the array brackets.","solutions":["Confirm the parent value at that path step is actually an array; if it's an object, use the string key instead of an index","Validate the document structure (json.loads on comment-stripped text, check isinstance(list)) before removal","Repair unbalanced brackets if the file was hand-edited","Catch ValueError and skip the edit, logging the file for manual follow-up"],"exampleFix":"# before\n# config: {\"servers\": {\"graph\": {}}}\nremove_jsonc_paths(text, [\"servers\", 0])  # -> expected JSON array\n\n# after\nremove_jsonc_paths(text, [\"servers\", \"graph\"])","handlingStrategy":"validation","validationCode":"import json, re\ndef resolves_to_array(text: str, path: list) -> bool:\n    try:\n        cur = json.loads(re.sub(r\"//[^\\n]*|/\\*.*?\\*/\", \"\", text, flags=re.S))\n        for c in path:\n            cur = cur[c]\n        return isinstance(cur, list)\n    except (ValueError, KeyError, IndexError, TypeError):\n        return False","typeGuard":"def is_int_path_component(c) -> bool:\n    return isinstance(c, int) and not isinstance(c, bool)","tryCatchPattern":"try:\n    _remove_jsonc_paths(text, paths)\nexcept ValueError as e:\n    log.warning(\"path shape mismatch: %s\", e)","preventionTips":["Confirm container type (array vs object) before using int indices","Pin path constants when config schema changes","Unit-test removal paths against a fixture config"],"tags":["json","jsonc","array","path-index","uninstall"],"backgroundTag":"json-parse-error","analyzedSha":"b58668751ab0c7670c078cf7cbd4d1f5b8e54f81","analyzedAt":"2026-08-28T13:19:08.966Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}