AFI: Revert filetype changes crashes with FileNotFoundError if the package is removed/upgraded shortly after running it
What happens
Running the "AFI: Revert filetype changes" command schedules follow-up cleanup work (remove_overlay in plugin.py) on a short async delay. Part of that follow-up calls settings.add_listener(), which reloads the package's own settings resource. If the package is removed or upgraded (Package Control does remove-then-reinstall on upgrade) in that short window before the delayed callback fires, the reload tries to read a settings file that no longer exists and throws uncaught:
Traceback (most recent call last):
File ".../A File Icon.sublime-package/plugin.py", line 35, in remove_overlay
File ".../A File Icon.sublime-package/core/settings.py", line 24, in add_listener
File ".../sublime.py", line 1199, in load_resource
raise FileNotFoundError(f'resource "{name}" not found')
FileNotFoundError: resource "Packages/A File Icon/A File Icon.sublime-settings" not found
Repro steps
- Install "A File Icon".
- Run "AFI: Revert filetype changes" from the Command Palette.
- Immediately remove or upgrade the package (before ~a couple of seconds pass).
- The console shows the traceback above.
Suggested fix
Wrap the follow-up settings reload (settings.add_listener() inside remove_overlay's finally block) in a try/except, the same defensive pattern already used elsewhere in the package (e.g. around clear_overlay).
Found via live testing while investigating whether Package Control packages are reliably controllable by automated tooling. Happy to provide more detail if useful.
Irrelevant and uncritical edge case
Oh My Pi deepseek-v4.1-flash reports:
Retested with A File Icon 4.0.1 on Sublime Text 4215 (Windows 11). The revert command and the remove_overlay path are gone in 4.0.1; the package now has only plugin_loaded/plugin_unloaded and the two afi_* commands. I could not reproduce the FileNotFoundError.
This is fixed in 4.0.1.