wustho / epy

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

Invalid search regex crashes the program with a traceback #7

Closed ghost closed 3 years ago

ghost commented 4 years ago

I've accidentally hit enter after /? and the program crashed with the following traceback:

Traceback (most recent call last):
  File "/usr/bin/epy", line 11, in <module>
    load_entry_point('epy==2020.4.17', 'console_scripts', 'epy')()
  File "/usr/lib64/python3.7/site-packages/epy.py", line 1437, in main
    curses.wrapper(preread, file)
  File "/usr/lib64/python3.7/curses/__init__.py", line 94, in wrapper
    return func(stdscr, *args, **kwds)
  File "/usr/lib64/python3.7/site-packages/epy.py", line 1336, in preread
    ebook, idx, width, y, pctg, sec
  File "/usr/lib64/python3.7/site-packages/epy.py", line 1159, in reader
    index, len(contents)
  File "/usr/lib64/python3.7/site-packages/epy.py", line 832, in searching
    pattern = re.compile(SEARCHPATTERN[1:], re.IGNORECASE)
  File "/usr/lib64/python3.7/re.py", line 234, in compile
    return _compile(pattern, flags)
  File "/usr/lib64/python3.7/re.py", line 286, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/usr/lib64/python3.7/sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "/usr/lib64/python3.7/sre_parse.py", line 930, in parse
    p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, 0)
  File "/usr/lib64/python3.7/sre_parse.py", line 426, in _parse_sub
    not nested and not items))
  File "/usr/lib64/python3.7/sre_parse.py", line 651, in _parse
    source.tell() - here + len(this))
re.error: nothing to repeat at position 0

You should probably catch this exception and instead display a relevant error message about an invalid regexp search string.

It's not a critical bug, yet epy seems to lose the current position in the file when crashing like that. Without looking at the code, I can assume it only saves position when exitting gracefully.

wustho commented 4 years ago

Thanks so much for the advice mate, will fix it later...

wustho commented 4 years ago

Sorry accidentally pressing close and comment issue. I'm using mobile phone

wustho commented 4 years ago

Hey there just fixed this: https://github.com/wustho/epy/commit/3349f99ed28b5c9884308fba969e7ec554a60415

Oh make sure you delete recursively config dir ~/.config/epy because I do some heavy config/state file update without considering backward compatibility, sorry.

ghost commented 4 years ago

Reinstalled the latest version and everything is fine now, thank you.