Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash on current sublime #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ctheune
Copy link
Contributor

@ctheune ctheune commented Feb 21, 2024

I've seen the plugin crash today:

reloading python 3.3 plugin sublime-rsync-ssh.rsync_ssh Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 308, in reload_plugin
    m = importlib.import_module(modulename)
  File "./python3.3/importlib/__init__.py", line 90, in import_module
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 584, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1022, in load_module
  File "<frozen importlib._bootstrap>", line 1003, in load_module
  File "<frozen importlib._bootstrap>", line 560, in module_for_loader_wrapper
  File "<frozen importlib._bootstrap>", line 868, in _load_module
  File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
  File "/Users/ctheune/Library/Application Support/Sublime Text 3/Packages/sublime-rsync-ssh/rsync_ssh.py", line 27, in <module>
    def console_show(window=sublime.active_window()):
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime.py", line 515, in active_window
    return Window(sublime_api.active_window())
RuntimeError: API is not available

This fixes it.

reloading python 3.3 plugin sublime-rsync-ssh.rsync_ssh
Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 308, in reload_plugin
    m = importlib.import_module(modulename)
  File "./python3.3/importlib/__init__.py", line 90, in import_module
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 584, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1022, in load_module
  File "<frozen importlib._bootstrap>", line 1003, in load_module
  File "<frozen importlib._bootstrap>", line 560, in module_for_loader_wrapper
  File "<frozen importlib._bootstrap>", line 868, in _load_module
  File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
  File "/Users/ctheune/Library/Application Support/Sublime Text 3/Packages/sublime-rsync-ssh/rsync_ssh.py", line 27, in <module>
    def console_show(window=sublime.active_window()):
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime.py", line 515, in active_window
    return Window(sublime_api.active_window())
RuntimeError: API is not available

This fixes it.
Comment on lines +27 to +28
if window is None:
sublime.active_window()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct. It doesn't set window variable.

BTW. This issue will likely be fixed in later ST builds (if it's not already in 4171).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW. The proper fix would be to change the argument to window instead of window=None and just return from this function if window is None.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch, lol, yeah. Too little coffee today. If that was a ST regression, then I'm happy to forget about this. This was a bit of a panic because my workflow completely broke this morning ... and yeah, it seems like this is in 4171 ...

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a proper fix would still be good because it looks like the original code could in some cases trigger a crash (in theory), if it's possible for window to be None. Or maybe the issue in those new builds is that run_command is not available to be used during plugin import so previously it was a noop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to fix that fix if you like. Using a default argument factory like this isn't quite Pythonic as it has lots of edge cases ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants