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

Random errors due to no selection #116

Closed
rchl opened this issue Aug 23, 2022 · 4 comments
Closed

Random errors due to no selection #116

rchl opened this issue Aug 23, 2022 · 4 comments

Comments

@rchl
Copy link

rchl commented Aug 23, 2022

I'm randomly getting errors like:

Traceback (most recent call last):
  File "../Packages/LSP/plugin/symbols.py", line 106, in <lambda>
    lambda response: sublime.set_timeout(lambda: self.handle_response(response)),
  File "../Packages/LSP/plugin/symbols.py", line 121, in handle_response
    self.view.run_command("lsp_selection_clear")
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime.py", line 1349, in run_command
    sublime_api.view_run_command(self.view_id, cmd, args)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 1496, in run_
    self.view.end_edit(edit)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime.py", line 1310, in end_edit
    sublime_api.view_end_edit(self.view_id, edit.edit_token)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 932, in on_selection_modified
    run_view_callbacks('on_selection_modified', view_id)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 708, in run_view_callbacks
    callback(v, *args)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 152, in profiler
    return event_handler(*args)
  File "../Packages/WakaTime/WakaTime.py", line 620, in on_selection_modified
    handle_activity(view)
  File "../Packages/WakaTime/WakaTime.py", line 409, in handle_activity
    append_heartbeat(entity, timestamp, is_write, view, project, folders)
  File "../Packages/WakaTime/WakaTime.py", line 426, in append_heartbeat
    rowcol = view.rowcol(selections[0].begin())
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime.py", line 1044, in __getitem__
    raise IndexError()
IndexError

It's not really that important how it's triggered IMO because in the ST API it's not guaranteed that selection is non-empty so plugin should never assume so and always check first.

@alanhamlett
Copy link
Member

Can you add this after line 424 in your WakaTime.py file:

print("SELECTIONS: ", selections)

Then check your ST console for the output? What I want to find is the value of selections because right before selections[0] the code checks to make sure selections is defined which should guarantee it has at least one item in the list. So, an IndexError doesn't make sense.

@rchl
Copy link
Author

rchl commented Aug 23, 2022

I don't have a way to reproduce it at the moment but "truthy" check is not enough due to how Selections object is implemented in ST. It defines:

    def __bool__(self):
        return self.view_id != 0

which doesn't check number of selections. The 3.8 plugin host does:

    def __bool__(self) -> bool:
        """ The selection is ``True`` when not empty. """
        return self.view_id != 0 and len(self) > 0

but that fix didn't trickle down to the old host.

So the explicit len(...) check is needed.

@alanhamlett
Copy link
Member

Oh, that's not normal in Python but I was assuming it behaved like a Python list. I'll submit a patch now.

@alanhamlett
Copy link
Member

Fixed in v11.0.8 released just now.

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

No branches or pull requests

2 participants