json loading error handling

main2
Bob Mottram 2019-10-26 13:47:27 +01:00
parent cf2be50b48
commit 5f94b413a7
4 changed files with 7 additions and 7 deletions

View File

@ -326,7 +326,7 @@ def addHtmlTags(baseDir: str,httpPrefix: str, \
if emojiDictCtr>0:
print('emojiDict loaded on try '+str(emojiDictCtr))
break
except commentjson.JSONLibraryException as e:
except (IndexError, AttributeError, commentjson.JSONLibraryException) as e:
print('WARN: commentjson exception addHtmlTags - '+str(e))
print('Failed to load emoji (try '+str(emojiDictCtr)+'): '+baseDir+'/emoji/emoji.json '+str(e))
time.sleep(1)

View File

@ -1727,7 +1727,7 @@ def runInboxQueue(projectVersion: str, \
try:
with open(queueFilename, 'r') as fp:
queueJson=commentjson.load(fp)
except commentjson.JSONLibraryException as e:
except (IndexError, AttributeError, commentjson.JSONLibraryException) as e:
itemReadFailed+=1
print('WARN: commentjson exception runInboxQueue - '+str(e))
print('WARN: Failed to load inbox queue item '+queueFilename+' (try '+str(itemReadFailed)+')')

View File

@ -1927,7 +1927,7 @@ def createSharedInboxIndex(baseDir: str,sharedBoxDir: str, \
try:
with open(sharedInboxFilename, 'r') as fp:
postJsonObject=commentjson.load(fp)
except commentjson.JSONLibraryException as e:
except (IndexError, AttributeError, commentjson.JSONLibraryException) as e:
print('WARN: commentjson exception createBoxBase - '+str(e))
continue
@ -1963,7 +1963,7 @@ def createSharedInboxIndex(baseDir: str,sharedBoxDir: str, \
with open(ocapFilename, 'r') as fp:
ocapJson=commentjson.load(fp)
loadedOcap=True
except commentjson.JSONLibraryException as e:
except (IndexError, AttributeError, commentjson.JSONLibraryException) as e:
print('WARN: commentjson exception createBoxBase - '+str(e))
if loadedOcap:

View File

@ -37,7 +37,7 @@ def loadJson(filename: str) -> {}:
with open(filename, 'r') as fp:
jsonObject=commentjson.load(fp)
break
except commentjson.JSONLibraryException as e:
except (IndexError, AttributeError, commentjson.JSONLibraryException) as e:
print('WARN: loadJson exception - '+str(e))
time.sleep(2)
tries+=1
@ -127,7 +127,7 @@ def getDisplayName(baseDir: str,actor: str,personCache: {}) -> str:
with open(cachedActorFilename, 'r') as fp:
actorJson=commentjson.load(fp)
break
except commentjson.JSONLibraryException as e:
except (IndexError, AttributeError, commentjson.JSONLibraryException) as e:
print('WARN: getDisplayName '+str(e))
time.sleep(1)
tries+=1
@ -300,7 +300,7 @@ def deletePost(baseDir: str,httpPrefix: str,nickname: str,domain: str,postFilena
with open(postFilename, 'r') as fp:
postJsonObject=commentjson.load(fp)
break
except commentjson.JSONLibraryException as e:
except (IndexError, AttributeError, commentjson.JSONLibraryException) as e:
print('WARN: deletePost '+str(e))
time.sleep(1)
tries+=1