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

Crash on startup when reading malformed history file #19

Closed
janmayer opened this issue Dec 8, 2020 · 1 comment
Closed

Crash on startup when reading malformed history file #19

janmayer opened this issue Dec 8, 2020 · 1 comment
Assignees

Comments

@janmayer
Copy link
Owner

janmayer commented Dec 8, 2020

If the hdtv_history file is damaged or malformed, hdtv will crash with a unhelpful error.

Traceback (most recent call last):
  File "./bin/hdtv", line 235, in <module>
    App()
  File "./bin/hdtv", line 178, in __init__
    hdtv.cmdline.MainLoop()
  File "/srv/storage/gpfs/user/jmayer/Development/hdtv/hdtv/cmdline.py", line 663, in MainLoop
    self.session = PromptSession(
  File "/home/jmayer/.pyenv/versions/3.8.5/lib/python3.8/site-packages/prompt_toolkit/shortcuts/prompt.py", line 463, in __init__
    self.default_buffer = self._create_default_buffer()
  File "/home/jmayer/.pyenv/versions/3.8.5/lib/python3.8/site-packages/prompt_toolkit/shortcuts/prompt.py", line 498, in _create_default_buffer
    return Buffer(
  File "/home/jmayer/.pyenv/versions/3.8.5/lib/python3.8/site-packages/prompt_toolkit/buffer.py", line 316, in __init__
    self.history.load(new_history_item)
  File "/home/jmayer/.pyenv/versions/3.8.5/lib/python3.8/site-packages/prompt_toolkit/history.py", line 70, in load
    for item in self.load_history_strings():
  File "/home/jmayer/.pyenv/versions/3.8.5/lib/python3.8/site-packages/prompt_toolkit/history.py", line 210, in load_history_strings
    line = line_bytes.decode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 0: unexpected end of data

To reproduce: echo -n -e '\xe9' >> ~/.local/share/hdtv/hdtv_history

We had one case of this, and I don't know what caused the damage to the file in the first place.
I'm not sure how to best mitigate that error with prompt_toolkit or tell the user his history file is damaged.

@op3
Copy link
Collaborator

op3 commented Dec 8, 2020

I guess this might happen if the user still has an old readline history that was not encoded using UTF-8?

This should probably be fixed in prompt_toolkit: prompt-toolkit/python-prompt-toolkit#1303

In the meantime, we can just catch the exception and replace malformed characters if necessary.

@op3 op3 closed this as completed in 52ef28a Dec 8, 2020
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