sublimehq / sublime_text

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

TypeError: 'NoneType' object is not iterable, PhantomSet.update([]) #5016

Open evandrocoan opened 3 years ago

evandrocoan commented 3 years ago

Description of the bug

When closing Sublime Text, it creates an error file Logs/plugin_host-3.8-on_exit.log, for an exception at \python38\sublime.py", line 1928

Exception ignored in: <function DocumentSyncListener.__del__ at 0x000002BDF650F670>
Traceback (most recent call last):
  File "F:\SublimeText\Data\Packages\LSP\plugin\documents.py", line 167, in __del__
    self._cleanup()
  File "F:\SublimeText\Data\Packages\LSP\plugin\documents.py", line 189, in _cleanup
    self._color_phantoms.update([])
  File "F:\SublimeText\Lib\python38\sublime.py", line 1928, in update
    for phantom, region in zip(self.phantoms, regions):
TypeError: 'NoneType' object is not iterable

On the code, either regions from self.view.query_phantoms is None or self.phantoms. It seems more probable self.view.query_phantoms is returning None:

File: F:/SublimeText/Lib/python38/sublime.py
1909: class PhantomSet:
1910:     def __init__(self, view, key=""):
1911:         self.view = view
1912:         self.key = key
1913:         self.phantoms = []
1914: 
1915:     def __del__(self):
1916:         for p in self.phantoms:
1917:             self.view.erase_phantom_by_id(p.id)
1918: 
1919:     def __repr__(self):
1920:         return f'PhantomSet({self.view!r}, key={self.key!r})'
1921: 
1922:     def update(self, new_phantoms):
1923:         new_phantoms = {p.to_tuple(): p for p in new_phantoms}
1924: 
1925:         # Update the list of phantoms that exist in the text buffer with their
1926:         # current location
1927:         regions = self.view.query_phantoms([p.id for p in self.phantoms])
1928:         for phantom, region in zip(self.phantoms, regions):
1929:             phantom.region = region

Steps to reproduce

Unsure happens on shutdown.

Expected behavior

Do not create the error file plugin_host-3.8-on_exit.log on shutdown, if there are no actual errors.

Actual behavior

Create the error file plugin_host-3.8-on_exit.log on shutdown.

Sublime Text build number

4121

Operating system & version

Windows 10

(Linux) Desktop environment and/or window manager

No response

Additional information

No response

OpenGL context information

No response

deathaxe commented 2 years ago

This issue is caused by LSP plugin as it accesses API after plugin_host has started shutting down.

rchl commented 2 years ago

This could and probably should be handled on the core side. Should be much simpler and universally better to handle it there.

I'm assuming that many of the other APIs won't have problem with being called after plugin unloaded so would say that this should just be fixed in core to do nothing.