Skip to content

Regression: malformed settings file blocks startup or is overwritten silently #146

Closed

Description

@TMHSDigital

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/UnicodeDecodeError returns defaults without quarantine or load_warning)
  • autoclicker/core/settings_paths.py:43-50 (_read_json suppresses only OSError and JSONDecodeError)
  • 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_warning

The 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

  1. Write {"click_interval": 250, "presets": {"Caf\u00e9": {}}} encoded as cp1252 to a settings path
  2. Construct SettingsManager(path) and call .set("click_interval", 100)
  3. load_warning is 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 and load_warning set
  • "max_cps_ceiling": "fast" and 1e400: app starts with the default ceiling
  • Tests cover both cases plus a PermissionError on 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) or tasks.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

  1. added
    bug
    priority: medium
    on Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpriority: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions