BerriAI/litellm · error · UpError
{path} contains invalid or unexpected JSON; cannot restore f
Error message
{path} contains invalid or unexpected JSON; cannot restore from it safely. What it means
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.
Source
Thrown at litellm/proxy/client/cli/commands/up.py:116
def write_backup(record: BackupRecord, backup_path: Path | None = None) -> None:
path: Final = backup_path if backup_path is not None else BACKUP_PATH
path.parent.mkdir(exist_ok=True)
with secure_create(path) as f:
json.dump({"existed": record.existed, "content": record.content}, f, indent=2)
def read_backup(backup_path: Path | None = None) -> BackupRecord | None:
path: Final = backup_path if backup_path is not None else BACKUP_PATH
if not path.exists():
return None
with open(path, "r") as f:
content: Final = f.read()
try:
return _BACKUP_RECORD_ADAPTER.validate_json(content)
except ValidationError:
raise UpError(f"{path} contains invalid or unexpected JSON; cannot restore from it safely.")
def restore_claude_settings(settings_path: Path | None = None, backup_path: Path | None = None) -> BackupRecord | None:
"""Restore settings_path from the backup at backup_path, then delete the backup.
Returns the restored record, or None if there was nothing to restore.
"""
resolved_settings_path: Final = settings_path if settings_path is not None else CLAUDE_SETTINGS_PATH
resolved_backup_path: Final = backup_path if backup_path is not None else BACKUP_PATH
record: Final = read_backup(resolved_backup_path)
if record is None:
return None
if record.existed and record.content is not None:
resolved_settings_path.parent.mkdir(parents=True, exist_ok=True)
with open(resolved_settings_path, "w") as f:
json.dump(record.content, f, indent=2)
elif resolved_settings_path.exists():
resolved_settings_path.unlink()View on GitHub (pinned to 77b7c6c40c)
Solutions
- Fix or remove the corrupt file so `lite up` can restore safely.
Example fix
Validate the file with python -m json.tool, or delete it and re-run lite up.
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at litellm/proxy/client/cli/commands/up.py:116 when the library encounters an invalid state.
Common situations: The backup/state file `lite up` restores from contains invalid JSON.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/5b157c521784a107.
Report an issue: GitHub.