sublimehq / sublime_text

Issue tracker for Sublime Text
https://www.sublimetext.com
809 stars 39 forks source link

`load_resource()` fails if called in `plugin_loaded()` #5555

Open deathaxe opened 2 years ago

deathaxe commented 2 years ago

Description of the bug

The load_resource() function fails loading resources from a sub directory of a package, when called directly in plugin_loaded() hook, while package is being enabled.

Steps to reproduce

  1. Start ST in SAFE MODE
  2. Create a Package named "Debug" in Data (Safe Mode)/Packages
  3. Add a child folder "py33" in "Debug".
  4. Add an empty "debug.json" with only an object {} in it.
  5. Add a plugin named "debug.py" in root of "Debug"

    import sublime
    
    def plugin_loaded():
       sublime.load_resource("Packages/Debug/py33/debug.json")
  6. Add "Debug" to "ignored_packages"
  7. Remove it. -> Exception thrown.

Expected behavior

All resources of a package should be available and accessible in plugin_loaded() function.

Actual behavior

load_resource() thows FileNotFoundError on python 3.8 or OSError on python 3.3 plugin_host, if the resource to load is located in a sub directory of the package.

reloading python 3.3 plugin Debug.debug
Traceback (most recent call last):
  File "C:\Apps\Sublime Text 40xx\Lib\python33\sublime_plugin.py", line 400, in load_module
    m.plugin_loaded()
  File "C:\Apps\Sublime Text 40xx\Data (Safe Mode)\Packages\Debug\debug.py", line 4, in plugin_loaded
    sublime.load_resource("Packages/Debug/py33/debug.json")
  File "C:\Apps\Sublime Text 40xx\Lib\python33\sublime.py", line 435, in load_resource
    raise IOError('resource "%s" not found' % name)
OSError: resource "Packages/Debug/py33/debug.json" not found

It happens if the package is removed from "ignored_packages" list.

It does not happen when reloading happens due to saving/modifying the file.

Note: This issue can/must currently be worked around by calling any function which makes use of load_resource() via sublime.set_timeout().

Sublime Text build number

4134

Operating system & version

Windows

(Linux) Desktop environment and/or window manager

No response

Additional information

No response

OpenGL context information

No response

UltraInstinct05 commented 2 years ago

I face the same issue using sublime.find_resources in CommandsBrowser. I worked around it using the aliter described, calling it in sublime.set_timeout