wustho / epy

CLI Ebook (epub2, epub3, fb2, mobi) Reader
GNU General Public License v3.0
928 stars 52 forks source link

Empty search string causes AssertionError #73

Closed dreamlayers closed 1 year ago

dreamlayers commented 1 year ago

I start reading an epub book, then hit the / key to start a search, and press enter without entering a search string. This is the result (with epy path removed to simplify it):

Traceback (most recent call last):
  File "epy.py", line 3976, in <module>
    main()
  File "epy.py", line 3966, in main
    filepath = curses.wrapper(preread, filepath)
  File "/usr/lib/python3.10/curses/__init__.py", line 94, in wrapper
    return func(stdscr, *args, **kwds)
  File "epy.py", line 3865, in preread
    reading_state_or_ebook = reader.read(reading_state)
  File "epy.py", line 3483, in read
    ret_object = self.searching(
  File "epy.py", line 2719, in searching
    assert isinstance(candidate_text, NoUpdate) or isinstance(candidate_text, Key)
AssertionError

This is in Ubuntu 22.10 with Python 3.10.7. Both cloning from here and installing via pip gives the same result. I think the proper thing to do would be to assume the user doesn't want to perform a search and get rid of the search prompt. I do see that this can be accomplished by pressing escape.

3N4N commented 1 year ago

This patch should fix it:

diff --git a/epy.py b/epy.py
index b9b1c1e400d5..b063775f841d 100755
--- a/epy.py
+++ b/epy.py
@@ -2724,7 +2724,8 @@ class Reader:
             if isinstance(candidate_text, str) and candidate_text:
                 self.search_data = SearchData(value=candidate_text)
             else:
-                assert isinstance(candidate_text, NoUpdate) or isinstance(candidate_text, Key)
+                if candidate_text != "":
+                    assert isinstance(candidate_text, NoUpdate) or isinstance(candidate_text, Key)
                 return candidate_text

         found = []

You can apply it thusly:

@wustho does this seem alright? You can patch it into master, then.

wustho commented 1 year ago

Hey guys, fixed with: https://github.com/wustho/epy/commit/fed6dc9e14566408bf527ea123092ce5511e05e9 Thanks!

dreamlayers commented 1 year ago

Yes, this fixes the issue. Thank you!