Skip to content

fix(cli): config set refuses to overwrite a corrupt config.json - #847

Closed
ebios-star wants to merge 1 commit into
entrius:testfrom
ebios-star:fix/config-set-refuse-overwrite-corrupt
Closed

fix(cli): config set refuses to overwrite a corrupt config.json#847
ebios-star wants to merge 1 commit into
entrius:testfrom
ebios-star:fix/config-set-refuse-overwrite-corrupt

Conversation

@ebios-star

Copy link
Copy Markdown
Contributor

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

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • Other

Testing

  • New `tests/cli/test_config_set_corruption.py` covers three cases:
    • corrupt existing JSON → exit 1, file untouched on disk (the critical invariant — the corrupt bytes must remain intact for inspection).
    • valid existing JSON → existing keys preserved when appending a new key.
    • missing file → fresh single-key config written.
  • `uv run --extra dev pytest tests/` — 646 tests pass (643 baseline + 3 new).

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Changes are documented (if applicable)

`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.
@xiao-xiao-mao xiao-xiao-mao Bot added the bug Something isn't working label Apr 28, 2026
@ebios-star

Copy link
Copy Markdown
Contributor Author

@anderdc @LandynDev — friendly ping for review when you have a moment.

Closes #845. gitt config set was the write-side counterpart to #816 / #817 (read-side) — when the existing config.json was corrupt JSON, it printed a yellow warning and overwrote with only the new key, silently destroying every other configured value (network, contract_address, ws_endpoint, …).

Same refuse-to-overwrite invariant as #781 (PATs file). The JSONDecodeError branch now raises SystemExit(1) with a clear error pointing at the file, leaving the corrupt bytes on disk for inspection. 3 new regression tests, including the on-disk-preservation invariant.

Independent of #813 (whitelist on config_set) — different sections of the same function, no merge conflict expected. Happy to rebase if needed.

@anderdc anderdc closed this Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] gitt config set destroys every other config key when existing config.json is corrupt JSON

2 participants