{"record":{"id":"1f1c7f1b2c676df0","repo":"sgl-project/sglang","slug":"failed-to-parse-json-content-from-file-normalized","errorCode":null,"errorMessage":"Failed to parse JSON content from file {normalized_input}","messagePattern":"Failed to parse JSON content from file (.+?)","errorType":"validation","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/distributed/device_communicators/mooncake_transfer_engine.py","lineNumber":43,"sourceCode":"def parse_ib_device_config(\n    ib_device_str: Optional[str],\n) -> Optional[Union[str, Dict[int, str]]]:\n    \"\"\"Parse IB device config from a shared string, JSON mapping, or JSON file.\"\"\"\n    if ib_device_str is None or not ib_device_str.strip():\n        return None\n\n    normalized_input = ib_device_str.strip()\n    if not normalized_input.endswith(\".json\") and not normalized_input.startswith(\"{\"):\n        return normalized_input\n\n    if normalized_input.endswith(\".json\"):\n        if not os.path.isfile(normalized_input):\n            raise RuntimeError(f\"File {normalized_input} does not exist.\")\n        try:\n            with open(normalized_input, \"r\", encoding=\"utf-8\") as file:\n                mapping = json.load(file)\n        except json.JSONDecodeError as exc:\n            raise RuntimeError(\n                f\"Failed to parse JSON content from file {normalized_input}\"\n            ) from exc\n        except (IOError, OSError) as exc:\n            raise RuntimeError(\n                f\"Failed to read JSON file {normalized_input}: {exc}\"\n            ) from exc\n    else:\n        try:\n            mapping = json.loads(normalized_input)\n        except json.JSONDecodeError as exc:\n            raise ValueError(f\"Invalid JSON mapping: {normalized_input}\") from exc\n\n    if not isinstance(mapping, dict):\n        raise ValueError(\n            \"Invalid format: expected a mapping from GPU id to IB device string\"\n        )\n\n    normalized_mapping: Dict[int, str] = {}","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/distributed/device_communicators/mooncake_transfer_engine.py#L25-L61","documentation":"The mooncake IB-device config pointed at an existing .json file, but json.load failed with JSONDecodeError — the file contents are not valid JSON (truncated, BOM, YAML/Python dict syntax, trailing commas). Raised by parse_ib_device_config with the offending path in the message, chained from the original JSONDecodeError which pinpoints the line/column.","triggerScenarios":"Passing a .json file whose content json.load cannot parse — malformed JSON, empty file, hand-edited mapping with single quotes or comments, or a file corrupted/truncated during provisioning.","commonSituations":"Writing the mapping by hand in YAML/Python style ({'0': 'mlx5_0'}), a partially-written file from a config generator, or an empty template shipped without being filled in.","solutions":["Validate the file with python -m json.tool /path/to/file.json; the chained JSONDecodeError shows the exact line/column","Rewrite the file as strict JSON, e.g. {\"0\": \"mlx5_0,mlx5_1\", \"1\": \"mlx5_2\"}","If the file is generated by a script, re-run the generator and verify it emits valid, fully-written JSON"],"exampleFix":"# before (gpu_ib_map.json)\n{'0': 'mlx5_0', '1': 'mlx5_2'}  # Python-style quotes -> JSONDecodeError\n\n# after\n{\"0\": \"mlx5_0\", \"1\": \"mlx5_2\"}","handlingStrategy":"validation","validationCode":"import json\n\ndef validate_ib_mapping_file(path: str) -> dict:\n    with open(path) as f:\n        return json.load(f)  # raises JSONDecodeError with line/column before server start","typeGuard":null,"tryCatchPattern":"try:\n    mapping = parse_ib_device_config(cfg)\nexcept (RuntimeError, ValueError) as e:\n    fail_deploy(f\"Invalid mooncake IB config: {e}\")  # abort before engine init","preventionTips":["Run python -m json.tool on the mapping file in CI/deploy scripts","Generate the file with a script (json.dump) instead of hand-editing","Never use Python-dict syntax (single quotes/comments) in the JSON file"],"tags":["json","config","mooncake","ib-devices"],"backgroundTag":"invalid-json-config","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}