AFileIcon icon indicating copy to clipboard operation
AFileIcon copied to clipboard

AFI: Revert filetype changes crashes with FileNotFoundError if the package is removed/upgraded shortly after running it

Open dpc00 opened this issue 2 months ago • 2 comments

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

  1. Install "A File Icon".
  2. Run "AFI: Revert filetype changes" from the Command Palette.
  3. Immediately remove or upgrade the package (before ~a couple of seconds pass).
  4. 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.

dpc00 avatar Sep 14 '26 21:09 dpc00

Irrelevant and uncritical edge case

deathaxe avatar Sep 15 '26 10:09 deathaxe

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.

dpc00 avatar Nov 04 '26 03:11 dpc00