Adding debug to exceptions

main
Bob Mottram 2021-10-29 17:31:20 +01:00
parent e89538de47
commit 99ae054cf2
8 changed files with 139 additions and 9 deletions

View File

@ -255,5 +255,5 @@ def recordLoginFailure(baseDir: str, ipAddress: str,
ipAddress + ' port 443: ' +
'Too many authentication failures [preauth]\n')
except BaseException:
print('WARN: recordLoginFailure failed ' + str(failureLog))
print('EX: recordLoginFailure failed ' + str(failureLog))
pass

View File

@ -517,7 +517,7 @@ def mutePost(baseDir: str, nickname: str, domain: str, port: int,
os.remove(cachedPostFilename)
print('MUTE: cached post removed ' + cachedPostFilename)
except BaseException:
print('WARN: MUTE cached post not removed ' +
print('EX: MUTE cached post not removed ' +
cachedPostFilename)
pass
else:
@ -556,7 +556,7 @@ def mutePost(baseDir: str, nickname: str, domain: str, port: int,
print('MUTE: cached referenced post removed ' +
cachedPostFilename)
except BaseException:
print('WARN: ' +
print('EX: ' +
'MUTE cached referenced post not removed ' +
cachedPostFilename)
pass
@ -589,7 +589,7 @@ def unmutePost(baseDir: str, nickname: str, domain: str, port: int,
os.remove(muteFilename)
except BaseException:
if debug:
print('WARN: unmutePost mute filename not deleted ' +
print('EX: unmutePost mute filename not deleted ' +
str(muteFilename))
pass
print('UNMUTE: ' + muteFilename + ' file removed')
@ -640,7 +640,7 @@ def unmutePost(baseDir: str, nickname: str, domain: str, port: int,
os.remove(cachedPostFilename)
except BaseException:
if debug:
print('WARN: unmutePost cached post not deleted ' +
print('EX: unmutePost cached post not deleted ' +
str(cachedPostFilename))
pass
@ -673,7 +673,7 @@ def unmutePost(baseDir: str, nickname: str, domain: str, port: int,
cachedPostFilename)
except BaseException:
if debug:
print('WARN: ' +
print('EX: ' +
'unmutePost cached ref post not removed ' +
str(cachedPostFilename))
pass
@ -819,7 +819,7 @@ def setBrochMode(baseDir: str, domainFull: str, enabled: bool) -> None:
try:
os.remove(allowFilename)
except BaseException:
print('WARN: setBrochMode allow file not deleted ' +
print('EX: setBrochMode allow file not deleted ' +
str(allowFilename))
pass
print('Broch mode turned off')
@ -874,7 +874,7 @@ def brochModeLapses(baseDir: str, lapseDays: int) -> bool:
modifiedDate = \
datetime.strptime(lastModified, "%Y-%m-%dT%H:%M:%SZ")
except BaseException:
print('WARN: brochModeLapses date not parsed ' + str(lastModified))
print('EX: brochModeLapses date not parsed ' + str(lastModified))
return False
if not modifiedDate:
return False
@ -886,7 +886,7 @@ def brochModeLapses(baseDir: str, lapseDays: int) -> bool:
os.remove(allowFilename)
removed = True
except BaseException:
print('WARN: brochModeLapses allow file not deleted ' +
print('EX: brochModeLapses allow file not deleted ' +
str(allowFilename))
pass
if removed:

View File

@ -52,6 +52,10 @@ def undoBookmarksCollectionEntry(recentPostsCache: {},
try:
os.remove(cachedPostFilename)
except BaseException:
if debug:
print('EX: undoBookmarksCollectionEntry ' +
'unable to delete cached post file ' +
str(cachedPostFilename))
pass
removePostFromCache(postJsonObject, recentPostsCache)
@ -160,6 +164,10 @@ def updateBookmarksCollection(recentPostsCache: {},
try:
os.remove(cachedPostFilename)
except BaseException:
if debug:
print('EX: updateBookmarksCollection ' +
'unable to delete cached post ' +
str(cachedPostFilename))
pass
removePostFromCache(postJsonObject, recentPostsCache)

View File

@ -27,6 +27,7 @@ def _removePersonFromCache(baseDir: str, personUrl: str,
try:
os.remove(cacheFilename)
except BaseException:
print('EX: unable to delete cached actor ' + str(cacheFilename))
pass
if personCache.get(personUrl):
del personCache[personUrl]

View File

@ -96,6 +96,9 @@ def updateHashtagCategories(baseDir: str) -> None:
try:
os.remove(categoryListFilename)
except BaseException:
print('EX: updateHashtagCategories ' +
'unable to delete cached category list ' +
categoryListFilename)
pass
return

View File

@ -272,6 +272,8 @@ def replaceEmojiFromTags(content: str, tag: [], messageType: str) -> str:
content = content.replace(tagItem['name'],
replaceChar)
except BaseException:
print('EX: replaceEmojiFromTags name ' +
str(iconName))
pass
else:
# sequence of codes
@ -283,6 +285,8 @@ def replaceEmojiFromTags(content: str, tag: [], messageType: str) -> str:
icode, 16))
except BaseException:
iconCodeSequence = ''
print('EX: replaceEmojiFromTags code ' +
str(icode))
break
if iconCodeSequence:
content = content.replace(tagItem['name'],
@ -943,11 +947,19 @@ def saveMediaInFormPOST(mediaBytes, debug: bool,
try:
os.remove(possibleOtherFormat)
except BaseException:
if debug:
print('EX: saveMediaInFormPOST ' +
'unable to delete other ' +
str(possibleOtherFormat))
pass
if os.path.isfile(filenameBase):
try:
os.remove(filenameBase)
except BaseException:
if debug:
print('EX: saveMediaInFormPOST ' +
'unable to delete ' +
str(filenameBase))
pass
if debug:
@ -1017,6 +1029,10 @@ def saveMediaInFormPOST(mediaBytes, debug: bool,
try:
os.remove(possibleOtherFormat)
except BaseException:
if debug:
print('EX: saveMediaInFormPOST ' +
'unable to delete other 2 ' +
str(possibleOtherFormat))
pass
# don't allow scripts within svg files

View File

@ -46,6 +46,8 @@ def updateConversation(baseDir: str, nickname: str, domain: str,
fp.write(postId + '\n')
return True
except BaseException:
print('EX: updateConversation ' +
'unable to write to ' + conversationFilename)
pass
elif postId + '\n' not in open(conversationFilename).read():
try:
@ -53,6 +55,8 @@ def updateConversation(baseDir: str, nickname: str, domain: str,
fp.write(postId + '\n')
return True
except BaseException:
print('EX: updateConversation 2 ' +
'unable to write to ' + conversationFilename)
pass
return False
@ -86,4 +90,6 @@ def unmuteConversation(baseDir: str, nickname: str, domain: str,
try:
os.remove(conversationFilename + '.muted')
except BaseException:
print('EX: unmuteConversation unable to delete ' +
conversationFilename + '.muted')
pass

View File

@ -541,6 +541,9 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(cachedPostFilename)
except BaseException:
print('EX: _sendReplyToQuestion ' +
'unable to delete ' +
cachedPostFilename)
pass
# remove from memory cache
removePostFromCache(postJsonObject,
@ -823,6 +826,8 @@ class PubServer(BaseHTTPRequestHandler):
with open(mediaFilename + '.etag', 'r') as etagFile:
etag = etagFile.read()
except BaseException:
print('EX: _set_headers_etag ' +
'unable to read ' + mediaFilename + '.etag')
pass
if not etag:
etag = md5(data).hexdigest() # nosec
@ -830,6 +835,8 @@ class PubServer(BaseHTTPRequestHandler):
with open(mediaFilename + '.etag', 'w+') as etagFile:
etagFile.write(etag)
except BaseException:
print('EX: _set_headers_etag ' +
'unable to write ' + mediaFilename + '.etag')
pass
# if etag:
# self.send_header('ETag', '"' + etag + '"')
@ -855,6 +862,8 @@ class PubServer(BaseHTTPRequestHandler):
with open(mediaFilename, 'r') as etagFile:
currEtag = etagFile.read()
except BaseException:
print('EX: _etag_exists unable to read ' +
str(mediaFilename))
pass
if currEtag and oldEtag == currEtag:
# The file has not changed
@ -2329,6 +2338,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(newswireBlockedFilename)
except BaseException:
print('EX: _personOptions unable to delete ' +
newswireBlockedFilename)
pass
refreshNewswire(self.server.baseDir)
else:
@ -2367,6 +2378,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(featuresBlockedFilename)
except BaseException:
print('EX: _personOptions unable to delete ' +
featuresBlockedFilename)
pass
refreshNewswire(self.server.baseDir)
else:
@ -2405,6 +2418,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(newswireModFilename)
except BaseException:
print('EX: _personOptions unable to delete ' +
newswireModFilename)
pass
else:
if os.path.isdir(accountDir):
@ -3838,6 +3853,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(linksFilename)
except BaseException:
print('EX: _linksUpdate unable to delete ' +
linksFilename)
pass
adminNickname = \
@ -3854,6 +3871,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(aboutFilename)
except BaseException:
print('EX: _linksUpdate unable to delete ' +
aboutFilename)
pass
if fields.get('editedTOS'):
@ -3867,6 +3886,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(TOSFilename)
except BaseException:
print('EX: _linksUpdate unable to delete ' +
TOSFilename)
pass
# redirect back to the default timeline
@ -3968,6 +3989,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(categoryFilename)
except BaseException:
print('EX: _setHashtagCategory unable to delete ' +
categoryFilename)
pass
# redirect back to the default timeline
@ -4049,6 +4072,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(newswireFilename)
except BaseException:
print('EX: _newswireUpdate unable to delete ' +
newswireFilename)
pass
# save filtered words list for the newswire
@ -4063,6 +4088,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(filterNewswireFilename)
except BaseException:
print('EX: _newswireUpdate unable to delete ' +
filterNewswireFilename)
pass
# save news tagging rules
@ -4076,6 +4103,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(hashtagRulesFilename)
except BaseException:
print('EX: _newswireUpdate unable to delete ' +
hashtagRulesFilename)
pass
newswireTrustedFilename = baseDir + '/accounts/newswiretrusted.txt'
@ -4090,6 +4119,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(newswireTrustedFilename)
except BaseException:
print('EX: _newswireUpdate unable to delete ' +
newswireTrustedFilename)
pass
# redirect back to the default timeline
@ -4118,6 +4149,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(citationsFilename)
except BaseException:
print('EX: _citationsUpdate unable to delete ' +
citationsFilename)
pass
if newswire and \
@ -4423,6 +4456,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(filenameBase)
except BaseException:
print('EX: _profileUpdate unable to delete ' +
filenameBase)
pass
else:
filenameBase = \
@ -4458,6 +4493,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(postImageFilename + '.etag')
except BaseException:
print('EX: _profileUpdate unable to delete ' +
postImageFilename + '.etag')
pass
city = getSpoofedCity(self.server.city,
@ -5493,6 +5530,9 @@ class PubServer(BaseHTTPRequestHandler):
os.remove(baseDir +
'/fonts/custom.' + ext)
except BaseException:
print('EX: _profileUpdate ' +
'unable to delete ' +
baseDir + '/fonts/custom.' + ext)
pass
if os.path.isfile(baseDir +
'/fonts/custom.' + ext +
@ -5502,6 +5542,10 @@ class PubServer(BaseHTTPRequestHandler):
'/fonts/custom.' + ext +
'.etag')
except BaseException:
print('EX: _profileUpdate ' +
'unable to delete ' +
baseDir + '/fonts/custom.' +
ext + '.etag')
pass
currTheme = getTheme(baseDir)
if currTheme:
@ -5553,6 +5597,9 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(followDMsFilename)
except BaseException:
print('EX: _profileUpdate ' +
'unable to delete ' +
followDMsFilename)
pass
# remove Twitter retweets
@ -5571,6 +5618,9 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(removeTwitterFilename)
except BaseException:
print('EX: _profileUpdate ' +
'unable to delete ' +
removeTwitterFilename)
pass
# hide Like button
@ -5591,12 +5641,18 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(notifyLikesFilename)
except BaseException:
print('EX: _profileUpdate ' +
'unable to delete ' +
notifyLikesFilename)
pass
if not hideLikeButtonActive:
if os.path.isfile(hideLikeButtonFile):
try:
os.remove(hideLikeButtonFile)
except BaseException:
print('EX: _profileUpdate ' +
'unable to delete ' +
hideLikeButtonFile)
pass
# notify about new Likes
@ -5618,6 +5674,9 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(notifyLikesFilename)
except BaseException:
print('EX: _profileUpdate ' +
'unable to delete ' +
notifyLikesFilename)
pass
# this account is a bot
@ -5680,6 +5739,9 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(filterFilename)
except BaseException:
print('EX: _profileUpdate ' +
'unable to delete ' +
filterFilename)
pass
# word replacements
@ -5694,6 +5756,9 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(switchFilename)
except BaseException:
print('EX: _profileUpdate ' +
'unable to delete ' +
switchFilename)
pass
# autogenerated tags
@ -5708,6 +5773,9 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(autoTagsFilename)
except BaseException:
print('EX: _profileUpdate ' +
'unable to delete ' +
autoTagsFilename)
pass
# autogenerated content warnings
@ -5722,6 +5790,9 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(autoCWFilename)
except BaseException:
print('EX: _profileUpdate ' +
'unable to delete ' +
autoCWFilename)
pass
# save blocked accounts list
@ -5736,6 +5807,9 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(blockedFilename)
except BaseException:
print('EX: _profileUpdate ' +
'unable to delete ' +
blockedFilename)
pass
# Save DM allowed instances list.
@ -5752,6 +5826,9 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(dmAllowedInstancesFilename)
except BaseException:
print('EX: _profileUpdate ' +
'unable to delete ' +
dmAllowedInstancesFilename)
pass
# save allowed instances list
@ -5767,6 +5844,9 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(allowedInstancesFilename)
except BaseException:
print('EX: _profileUpdate ' +
'unable to delete ' +
allowedInstancesFilename)
pass
if isModerator(self.server.baseDir, nickname):
@ -5830,6 +5910,9 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(peertubeInstancesFile)
except BaseException:
print('EX: _profileUpdate ' +
'unable to delete ' +
peertubeInstancesFile)
pass
self.server.peertubeInstances.clear()
@ -5845,6 +5928,9 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(gitProjectsFilename)
except BaseException:
print('EX: _profileUpdate ' +
'unable to delete ' +
gitProjectsFilename)
pass
# save actor json file within accounts
@ -15082,6 +15168,8 @@ class PubServer(BaseHTTPRequestHandler):
with open(mediaTagFilename, 'r') as etagFile:
etag = etagFile.read()
except BaseException:
print('EX: do_HEAD unable to read ' +
mediaTagFilename)
pass
else:
with open(mediaFilename, 'rb') as avFile:
@ -15091,6 +15179,8 @@ class PubServer(BaseHTTPRequestHandler):
with open(mediaTagFilename, 'w+') as etagFile:
etagFile.write(etag)
except BaseException:
print('EX: do_HEAD unable to write ' +
mediaTagFilename)
pass
mediaFileType = mediaFileMimeType(checkPath)
@ -15257,6 +15347,8 @@ class PubServer(BaseHTTPRequestHandler):
with open(lastUsedFilename, 'w+') as lastUsedFile:
lastUsedFile.write(str(int(time.time())))
except BaseException:
print('EX: _receiveNewPostProcess unable to write ' +
lastUsedFilename)
pass
mentionsStr = ''
@ -15420,6 +15512,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(cachedFilename)
except BaseException:
print('EX: _receiveNewPostProcess ' +
'unable to delete ' + cachedFilename)
pass
# remove from memory cache
removePostFromCache(postJsonObject,
@ -15843,6 +15937,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
os.remove(filename)
except BaseException:
print('EX: _receiveNewPostProcess ' +
'unable to delete ' + filename)
pass
self.postToNickname = nickname
return 1