Skip to content

Commit acaa8a1

Browse files
authored
Added code to process-reboot-check that mitigates JSON decoder errors
1 parent 3d8f196 commit acaa8a1

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/sonic-host-services/scripts/process-reboot-cause

+10-6
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,16 @@ def read_reboot_cause_files_and_save_state_db():
5252
x = TIME_SORTED_FULL_REBOOT_FILE_LIST[i]
5353
if os.path.isfile(x):
5454
with open(x, "r") as cause_file:
55-
data = json.load(cause_file)
56-
_hash = '{}|{}'.format(REBOOT_CAUSE_TABLE_NAME, data['gen_time'])
57-
state_db.set(state_db.STATE_DB, _hash, 'cause', data['cause'])
58-
state_db.set(state_db.STATE_DB, _hash, 'time', data['time'])
59-
state_db.set(state_db.STATE_DB, _hash, 'user', data['user'])
60-
state_db.set(state_db.STATE_DB, _hash, 'comment', data['comment'])
55+
try:
56+
data = json.load(cause_file)
57+
_hash = '{}|{}'.format(REBOOT_CAUSE_TABLE_NAME, data['gen_time'])
58+
state_db.set(state_db.STATE_DB, _hash, 'cause', data['cause'])
59+
state_db.set(state_db.STATE_DB, _hash, 'time', data['time'])
60+
state_db.set(state_db.STATE_DB, _hash, 'user', data['user'])
61+
state_db.set(state_db.STATE_DB, _hash, 'comment', data['comment'])
62+
except json.decoder.JSONDecodeError as je:
63+
sonic_logger.log_info("Unable to process reload cause file {}: {}".format(x, je))
64+
pass
6165

6266
if len(TIME_SORTED_FULL_REBOOT_FILE_LIST) > 10:
6367
for i in range(len(TIME_SORTED_FULL_REBOOT_FILE_LIST)):

0 commit comments

Comments
 (0)