Repository navigation
Description
Summary
#65 made corrupt settings files get moved aside instead of overwritten. Two cases still slip through: a file that is not UTF-8, and a numeric setting holding a non-numeric string. Depending on the path, the app either refuses to start on every launch or loads defaults and overwrites the user's file.
Where
autoclicker/core/settings_manager.py:273-275(OSError/UnicodeDecodeErrorreturns defaults without quarantine orload_warning)autoclicker/core/settings_paths.py:43-50(_read_jsonsuppresses onlyOSErrorandJSONDecodeError)autoclicker/app/controller.py:115-121(int(self.settings.get("max_cps_ceiling", 50))at startup)autoclicker/main.py:72-80
Details
except json.JSONDecodeError as e:
self._quarantine("is not valid JSON")
return self._defaults()
except (OSError, UnicodeDecodeError) as e:
_log.warning("Could not load settings file: %s", e)
return self._defaults() # no quarantine, no load_warningThe docstring says an unreadable file is "never overwritten by the next save", but this branch returns defaults and the next set() replaces the file. Separately, resolve_settings_file() reads the file through _read_json, which lets UnicodeDecodeError escape before SettingsManager is reached. _has_valid_type accepts any string for numeric keys, so "max_cps_ceiling": "fast" (or 1e400) makes apply_safety_from_settings raise ValueError/OverflowError. Both end in "Application failed to start".
Impact
A settings file saved as ANSI or UTF-16 (for example after editing in Notepad with an accented profile name) or a hand-edited value blocks startup until the user finds and deletes the file, or silently loses profiles and hotkeys.
Steps to reproduce
- Write
{"click_interval": 250, "presets": {"Caf\u00e9": {}}}encoded as cp1252 to a settings path - Construct
SettingsManager(path)and call.set("click_interval", 100) load_warningis None, no.corrupt-*file exists, and the original file has been replaced
Suggested fix
Route UnicodeDecodeError through _quarantine("is not UTF-8 text"), and catch it in _read_json too. For OSError (locked file), set load_warning and avoid saving over the file. Parse numeric settings with the existing parsers when applying them at startup and fall back to the default on error (or validate numeric keys in _merge_with_defaults).
Acceptance criteria
- Non-UTF-8 settings file: original bytes preserved in a
.corrupt-*sibling andload_warningset -
"max_cps_ceiling": "fast"and1e400: app starts with the default ceiling - Tests cover both cases plus a
PermissionErroron open
Related: #65
Getting started
- Relevant files:
autoclicker/core/settings_manager.py,autoclicker/core/settings_paths.py,tests/test_settings_manager.py - How to run tests:
make check(Git Bash) ortasks.bat lint,tasks.bat typecheck,tasks.bat test(cmd). Single test:python -m pytest tests/test_x.py::TestClass::test_name --no-cov - Related docs:
CONTRIBUTING.md,docs/ARCHITECTURE.md
Filed by repo-audit/full-audit at 9968dc8. Severity: medium. Effort: S. audit-key: bug|autoclicker/core/settings_manager.py|_load_settings
Activity