Skip to content

Commit 916060b

Browse files
committed
Fix a bug discovered during manual testing
I found that at least with certain versions of Python and OSes, if I had a previous text-based readline history, an unhandled UnpicklingError exception could occur. So now we catch that and several other possible errors which can theoretically occur during unpickling and just move on with an empty history. The old file will get overwritten with one in the new format when the application exits.
1 parent f82c365 commit 916060b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

cmd2/cmd2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3479,7 +3479,8 @@ def _initialize_history(self, hist_file):
34793479
try:
34803480
with open(hist_file, 'rb') as fobj:
34813481
history = pickle.load(fobj)
3482-
except (FileNotFoundError, KeyError, EOFError):
3482+
except (AttributeError, EOFError, FileNotFoundError, ImportError, IndexError, KeyError, pickle.UnpicklingError):
3483+
# If any non-operating system error occurs when attempting to unpickle, just use an empty history
34833484
pass
34843485
except OSError as ex:
34853486
msg = "can not read persistent history file '{}': {}"

0 commit comments

Comments
 (0)