{"record":{"id":"5b157c521784a107","repo":"BerriAI/litellm","slug":"path-contains-invalid-or-unexpected-json-cannot","errorCode":null,"errorMessage":"{path} contains invalid or unexpected JSON; cannot restore from it safely.","messagePattern":"(.+?) contains invalid or unexpected JSON; cannot restore from it safely\\.","errorType":"exception","errorClass":"UpError","httpStatus":null,"severity":"error","filePath":"litellm/proxy/client/cli/commands/up.py","lineNumber":116,"sourceCode":"\n\ndef write_backup(record: BackupRecord, backup_path: Path | None = None) -> None:\n    path: Final = backup_path if backup_path is not None else BACKUP_PATH\n    path.parent.mkdir(exist_ok=True)\n    with secure_create(path) as f:\n        json.dump({\"existed\": record.existed, \"content\": record.content}, f, indent=2)\n\n\ndef read_backup(backup_path: Path | None = None) -> BackupRecord | None:\n    path: Final = backup_path if backup_path is not None else BACKUP_PATH\n    if not path.exists():\n        return None\n    with open(path, \"r\") as f:\n        content: Final = f.read()\n    try:\n        return _BACKUP_RECORD_ADAPTER.validate_json(content)\n    except ValidationError:\n        raise UpError(f\"{path} contains invalid or unexpected JSON; cannot restore from it safely.\")\n\n\ndef restore_claude_settings(settings_path: Path | None = None, backup_path: Path | None = None) -> BackupRecord | None:\n    \"\"\"Restore settings_path from the backup at backup_path, then delete the backup.\n\n    Returns the restored record, or None if there was nothing to restore.\n    \"\"\"\n    resolved_settings_path: Final = settings_path if settings_path is not None else CLAUDE_SETTINGS_PATH\n    resolved_backup_path: Final = backup_path if backup_path is not None else BACKUP_PATH\n    record: Final = read_backup(resolved_backup_path)\n    if record is None:\n        return None\n    if record.existed and record.content is not None:\n        resolved_settings_path.parent.mkdir(parents=True, exist_ok=True)\n        with open(resolved_settings_path, \"w\") as f:\n            json.dump(record.content, f, indent=2)\n    elif resolved_settings_path.exists():\n        resolved_settings_path.unlink()","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/client/cli/commands/up.py#L98-L134","documentation":"Raised by read_backup in the CLI up command when the config backup file at BACKUP_PATH parses as JSON but does not match the expected {'existed', 'content'} BackupRecord shape (or fails to parse). Because `up` may need to restore the original config on failure, it refuses to restore from a backup it cannot trust and aborts; the path is embedded in the message.","triggerScenarios":"Thrown at litellm/proxy/client/cli/commands/up.py:116 when the library encounters an invalid state.","commonSituations":"The backup/state file `lite up` restores from contains invalid JSON.","solutions":["Fix or remove the corrupt file so `lite up` can restore safely."],"exampleFix":"Validate the file with python -m json.tool, or delete it and re-run lite up.","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}