mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
fixed JSON history corruption
This commit is contained in:
parent
88647b4a8f
commit
5a958bfe71
3 changed files with 24 additions and 4 deletions
|
@ -1,8 +1,6 @@
|
|||
**Added:** None
|
||||
|
||||
**Changed:**
|
||||
|
||||
* ``xip`` is now ``xpip``, because of a conflict with the Mac OSX archive format
|
||||
**Changed:** None
|
||||
|
||||
**Deprecated:** None
|
||||
|
||||
|
|
13
news/hiscor.rst
Normal file
13
news/hiscor.rst
Normal file
|
@ -0,0 +1,13 @@
|
|||
**Added:** None
|
||||
|
||||
**Changed:** None
|
||||
|
||||
**Deprecated:** None
|
||||
|
||||
**Removed:** None
|
||||
|
||||
**Fixed:**
|
||||
|
||||
* Made JSON history loading more robust to corrupt files.
|
||||
|
||||
**Security:** None
|
|
@ -1,7 +1,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""Implements JSON version of xonsh history backend."""
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
import builtins
|
||||
import collections
|
||||
import threading
|
||||
|
@ -396,7 +398,14 @@ class JsonHistory(History):
|
|||
except ValueError:
|
||||
# Invalid json file
|
||||
continue
|
||||
commands = json_file.load()['cmds']
|
||||
try:
|
||||
commands = json_file.load()['cmds']
|
||||
except json.decoder.JSONDecodeError:
|
||||
# file is corrupted somehow
|
||||
if builtins.__xonsh_env__.get('XONSH_DEBUG') > 0:
|
||||
msg = 'xonsh history file {0!r} is not valid JSON'
|
||||
print(msg.format(f), file=sys.stderr)
|
||||
continue
|
||||
for c in commands:
|
||||
yield {'inp': c['inp'].rstrip(), 'ts': c['ts'][0]}
|
||||
# all items should also include session items
|
||||
|
|
Loading…
Add table
Reference in a new issue