diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-05-27 14:02:56 -0400 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-05-27 14:02:56 -0400 |
commit | 916060bde828d8911ec2bbb4db54396212514481 (patch) | |
tree | 11dc0925c2225e37c9c99a37adfb421e24e6e02e | |
parent | f82c3653088f15bb33e2624fa0a3b5e9a6e74fb7 (diff) | |
download | cmd2-git-916060bde828d8911ec2bbb4db54396212514481.tar.gz |
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.
-rw-r--r-- | cmd2/cmd2.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 3c4c3308..e4fe6efa 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -3479,7 +3479,8 @@ class Cmd(cmd.Cmd): try: with open(hist_file, 'rb') as fobj: history = pickle.load(fobj) - except (FileNotFoundError, KeyError, EOFError): + except (AttributeError, EOFError, FileNotFoundError, ImportError, IndexError, KeyError, pickle.UnpicklingError): + # If any non-operating system error occurs when attempting to unpickle, just use an empty history pass except OSError as ex: msg = "can not read persistent history file '{}': {}" |