fix(cli): config set refuses to overwrite a corrupt config.json - #847
fix(cli): config set refuses to overwrite a corrupt config.json#847ebios-star wants to merge 1 commit into
Conversation
`gitt config set` previously caught `json.JSONDecodeError` on the existing config, printed a yellow "starting fresh" warning, then wrote back a fresh dict containing only the new key — silently destroying every other configured value (`network`, `contract_address`, `ws_endpoint`, `hotkey`, …) on a single mid-write crash or on-disk corruption. After this change the JSONDecodeError branch raises SystemExit(1) with a clear error pointing at the file, leaving the corrupt bytes on disk so the operator can inspect or remove them before re-running. Same refuse-to-overwrite invariant as entrius#781 (PATs file) and the read-side fix in entrius#817 (load_config + _load_config_value). Add `tests/cli/test_config_set_corruption.py` covering three cases: - corrupt existing JSON → exit 1, file untouched on disk - valid existing JSON → existing keys preserved on append - missing file → fresh single-key config written Closes entrius#845.
|
@anderdc @LandynDev — friendly ping for review when you have a moment. Closes #845. Same refuse-to-overwrite invariant as #781 (PATs file). The JSONDecodeError branch now raises Independent of #813 (whitelist on |
Summary
Closes #845.
`gitt config set` previously caught `json.JSONDecodeError` on the existing config, printed a yellow "starting fresh" warning, then wrote back a fresh dict containing only the new key — silently destroying every other configured value (`network`, `contract_address`, `ws_endpoint`, `hotkey`, …) on a single mid-write crash or on-disk corruption.
After this change the JSONDecodeError branch raises `SystemExit(1)` with a clear error pointing at the file, leaving the corrupt bytes on disk so the operator can inspect or remove them before re-running. Same refuse-to-overwrite invariant as #781 (PATs file) and the read-side fix in #817 (`load_config` + `_load_config_value`).
```
$ gitt config set wallet alice
Error: Existing config file at /home/me/.gittensor/config.json is not valid JSON (Expecting value: line 1 column 1 (char 0)).
Refusing to overwrite — inspect or remove the file before re-running.
$ echo $?
1
```
Related Issues
Closes #845. Same family as #781 (write side, PATs) and #817 (read side, this same file).
Type of Change
Testing
Checklist