Skip to content

FileExistsError on Windows when writing history backup file #41

Open

Description

@dpc00

`write_json_file` in `core/init.py` (called from `persist_requests`, which every successful request triggers) writes history atomically via a temp file renamed to a `.bkp` backup path:

```
File "core/init.py", line 407, in write_json_file
FileExistsError: [WinError 183] Cannot create a file when that file already exists: '...\Packages\User\Requester.history.json' -> '...\Packages\User\Requester.history.json.bkp'
```

`os.rename()` on POSIX silently overwrites an existing destination; on Windows it raises `FileExistsError` instead if the destination already exists. Since `Requester.history.json.bkp` already existed on this machine from a prior run, the very next request crashed here.

Reproduction: run any request once (creating `Requester.history.json.bkp`), then run a second request -- the second one hits the `.bkp` rename and raises.

The exception doesn't visibly break the visible request/response flow (the response tab still renders correctly), so it's easy to miss unless the console is checked -- this was found via a full console read, not a failed request.

Suggested fix: use `os.replace()` instead of `os.rename()` for the backup step -- `os.replace()` is documented to overwrite an existing destination atomically on both POSIX and Windows.

Sublime Text 4200, Windows.

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions