cpbotha / nvpy

Simplenote syncing note-taking application, inspired by Notational Velocity and ResophNotes, but uglier and cross-platformerer.
Other
849 stars 114 forks source link

Crash related to 'layout = vertical' and 'print_columns = 1' #200

Closed ernstki closed 11 months ago

ernstki commented 4 years ago

Using Python 3.6.9 on elementaryOS 5.1 Hera (Ubuntu 18.04-based), python3-tk 3.6.9-1~18.04 from the distro repositories; installed nvpy 2.0.2 with pip install --user by pointing directly at the GitHub repository about 30 minutes ago.

I've got years worth of notes in my Simplenote account, many of which use Unicode characters, which is the only way I discovered issue #44, which gave me the idea of disabling print_columns in my config file. So that is a workaround, for now.

With layout = vertical and print_columns = 1, however, I get this stacktrace immediately upon start. Hard for me to discern what it has to do with Unicode or columns, but here goes:

2020-01-15 20:34:43,907 - DEBUG - nvpy logging initialized
2020-01-15 20:34:43,907 - DEBUG - config read from ['/home/myuser/.nvpy.cfg']
2020-01-15 20:34:44,078 - CRITICAL - 
ERROR: An unexpected error occurred.
Thread(ident=139967026464576, name=MainThread)
Traceback (most recent call last):
  File "/home/myuser/.local/lib/python3.6/site-packages/nvpy/debug.py", line 30, in wrapper
    return fn(*args, **kwargs)
  File "/home/myuser/.local/lib/python3.6/site-packages/nvpy/tk.py", line 30, in wrapper
    return fn(*args, **kwargs)
  File "/home/myuser/.local/lib/python3.6/site-packages/nvpy/view.py", line 1899, in observer_notes_list
    self.set_notes(notes_list_model.list)
  File "/home/myuser/.local/lib/python3.6/site-packages/nvpy/view.py", line 2002, in set_notes
    self.notes_list.append(o.note, NoteConfig(tagfound=o.tagfound))
  File "/home/myuser/.local/lib/python3.6/site-packages/nvpy/view.py", line 520, in append
    self.text.insert(tk.END, u'{0:<{w}}'.format(title[:cellwidth - 1], w=cellwidth), ("title,"))
TypeError: slice indices must be integers or None or have an __index__ method

Other threads appear to be busy syncing notes happily, but this one seems to be what crashes the UI.

I see these other exceptions in the log (_tkinter.TclError: can't set "PY_VAR1" and ValueError: I/O operation on closed file.), but can't be sure if they're related:

Traceback: _tkinter.TclError: can't set "PY_VAR1"
2020-01-15 20:17:11,738 - ERROR - Traceback (most recent call last):
  File "/home/myuser/.local/lib/python3.6/site-packages/nvpy/debug.py", line 30, in wrapper
    return fn(*args, **kwargs)
  File "/home/myuser/.local/lib/python3.6/site-packages/nvpy/tk.py", line 30, in wrapper
    return fn(*args, **kwargs)
  File "/home/myuser/.local/lib/python3.6/site-packages/nvpy/nvpy.py", line 443, in observer_notes_db_sync_full
    self.view.refresh_notes_list()
  File "/home/myuser/.local/lib/python3.6/site-packages/nvpy/view.py", line 1094, in refresh_notes_list
    self.set_search_entry_text(self.get_search_entry_text())
  File "/home/myuser/.local/lib/python3.6/site-packages/nvpy/view.py", line 1153, in set_search_entry_text
    self.search_entry_var.set(text)
  File "/usr/lib/python3.6/tkinter/__init__.py", line 344, in set
    return self._tk.globalsetvar(self._name, value)
_tkinter.TclError: can't set "PY_VAR1": 

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/tkinter/__init__.py", line 1705, in __call__
    return self.func(*args)
  File "/usr/lib/python3.6/tkinter/__init__.py", line 749, in callit
    func(*args)
  File "/home/myuser/.local/lib/python3.6/site-packages/nvpy/view.py", line 2104, in fn
    callback()
  File "/home/myuser/.local/lib/python3.6/site-packages/nvpy/nvpy.py", line 422, in poll_notifies
    self.notes_db.handle_notifies()
  File "/home/myuser/.local/lib/python3.6/site-packages/nvpy/utils.py", line 222, in handle_notifies
    self.__invoke_observer(o, evt_type, evt)
  File "/home/myuser/.local/lib/python3.6/site-packages/nvpy/utils.py", line 229, in __invoke_observer
    observer(self, event_type, event)
  File "/home/myuser/.local/lib/python3.6/site-packages/nvpy/debug.py", line 51, in wrapper
    pdb.post_mortem(tb)
  File "/usr/lib/python3.6/pdb.py", line 1601, in post_mortem
    p.interaction(None, t)
  File "/usr/lib/python3.6/pdb.py", line 352, in interaction
    self._cmdloop()
  File "/usr/lib/python3.6/pdb.py", line 321, in _cmdloop
    self.cmdloop()
  File "/usr/lib/python3.6/cmd.py", line 126, in cmdloop
    line = input(self.prompt)
ValueError: I/O operation on closed file.

If anyone has ideas of how to narrow this down to which specific note(s) are causing the problem, I'd be happy to add extra detail to this issue. I'll even add a test to reproduce this behavior, if I had some idea where to start.

yuuki0xff commented 11 months ago

This bug was caused by the Python 3 migration. Python 3 changes the behavior of the "/" operator. On Python 3 environment, cellwidth - 1 should be int or float type. title[:cellwidth - 1] raises TypeError if cellwidth is float type.

Python 3.11.5 (main, Aug 29 2023, 15:31:31) [GCC 13.2.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.9.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: 3/2
Out[1]: 1.5

In [2]: notes = []

In [3]: notes[:1.5]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], line 1
----> 1 notes[:1.5]

TypeError: slice indices must be integers or None or have an __index__ method
yuuki0xff commented 11 months ago

Thanks for the detailed report. Very helpful for debugging.

ernstki commented 10 months ago

This bug was caused by the Python 3 migration. Python 3 changes the behavior of the "/" operator. On Python 3 environment, cellwidth - 1 should be int or float type. title[:cellwidth - 1] raises TypeError if cellwidth is float type.

Oh, that makes sense. Thank you!