Skip to content

Commit

Permalink
Increased exception logging to show offending line
Browse files Browse the repository at this point in the history
  • Loading branch information
ukdtom committed May 5, 2016
1 parent dadf01a commit 95f1370
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 66 deletions.
16 changes: 8 additions & 8 deletions Contents/Code/findMedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import urllib
import unicodedata
import json
import time
import time, sys

# Consts used here
AmountOfMediasInDatabase = 0 # Int of amount of medias in a database section
Expand Down Expand Up @@ -152,10 +152,10 @@ def setSetting(self, req):
req.clear()
req.set_status(200)
except Exception, e:
Log.Debug('Fatal error in setSetting: ' + str(e))
Log.Debug('Fatal error in setSetting: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
req.clear()
req.set_status(500)
req.finish("Unknown error happened in findMedia-setSetting: " + str(e))
req.finish("Unknown error happened in findMedia-setSetting: " + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))


# Reset settings to default
Expand Down Expand Up @@ -272,7 +272,7 @@ def scanMedias(sectionNumber, sectionLocations, sectionType, req):
except ValueError:
Log.Info('Aborted in ScanMedias')
except Exception, e:
Log.Critical('Exception happend in scanMedias: ' + str(e))
Log.Critical('Exception happend in scanMedias: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
statusMsg = 'Idle'

# Scan the file system
Expand Down Expand Up @@ -320,7 +320,7 @@ def getFiles(filePath):
runningState = 99
Log.Info('Aborted in getFiles')
except Exception, e:
Log.Critical('Exception happend in getFiles: ' + str(e))
Log.Critical('Exception happend in getFiles: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
runningState = 99

def scanShowDB(sectionNumber=0):
Expand Down Expand Up @@ -397,7 +397,7 @@ def scanShowDB(sectionNumber=0):
runningState = 99
Log.Info('Aborted in ScanShowDB')
except Exception, e:
Log.Debug('Fatal error in scanShowDB: ' + str(e))
Log.Debug('Fatal error in scanShowDB: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
runningState = 99
# End scanShowDB

Expand Down Expand Up @@ -440,7 +440,7 @@ def scanMovieDb(sectionNumber=0):
break
return
except Exception, e:
Log.Debug('Fatal error in scanMovieDb: ' + str(e))
Log.Debug('Fatal error in scanMovieDb: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
runningState = 99
# End scanMovieDb

Expand Down Expand Up @@ -472,7 +472,7 @@ def scanMovieDb(sectionNumber=0):
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Scanning already in progress')
except Exception, ex:
Log.Debug('Fatal error happened in scanSection: ' + str(ex))
Log.Debug('Fatal error happened in scanSection: ' + str(ex) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
Expand Down
52 changes: 26 additions & 26 deletions Contents/Code/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import datetime # Used for a timestamp in the dict
import json
import io, os, shutil
import io, os, shutil, sys
import plistlib
import pms
import tempfile
Expand Down Expand Up @@ -37,7 +37,7 @@ def __init__(self):
Log.Critical('UAS dir was missing the json, so doing a forced download here')
self.updateUASCache(None, cliForce = True)
except Exception, e:
Log.Critical('Exception happend when trying to force download from UASRes: ' + str(e))
Log.Critical('Exception happend when trying to force download from UASRes: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))

''' Grap the tornado req, and process it for GET request'''
def reqprocess(self, req):
Expand Down Expand Up @@ -157,7 +157,7 @@ def removeEmptyFolders(path, removeRoot=True):
Core.storage.save(path, data)
except Exception, e:
bError = True
Log.Critical('Exception happend in downloadBundle2tmp: ' + str(e))
Log.Critical('Exception happend in downloadBundle2tmp: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
else:
# We got a directory here
Log.Debug(filename.split('/')[-2])
Expand All @@ -169,7 +169,7 @@ def removeEmptyFolders(path, removeRoot=True):
Core.storage.ensure_dirs(path)
except Exception, e:
bError = True
Log.Critical('Exception happend in downloadBundle2tmp: ' + str(e))
Log.Critical('Exception happend in downloadBundle2tmp: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
# Now we need to nuke files that should no longer be there!
for root, dirs, files in os.walk(bundleName):
for fname in files:
Expand All @@ -188,7 +188,7 @@ def removeEmptyFolders(path, removeRoot=True):
except Exception, e:
Log.Critical('***************************************************************')
Log.Critical('Error when updating WebTools')
Log.Critical('The error was: ' + str(e))
Log.Critical('The error was: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
Log.Critical('***************************************************************')
Log.Critical('DARN....When we tried to upgrade WT, we had an error :-(')
Log.Critical('Only option now might be to do a manual install, like you did the first time')
Expand Down Expand Up @@ -226,7 +226,7 @@ def getUpdateList(self, req):
req.clear()
req.set_status(204)
except Exception, e:
Log.Debug('Fatal error happened in getUpdateList: ' + str(e))
Log.Critical('Fatal error happened in getUpdateList: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
Expand All @@ -252,7 +252,7 @@ def getUASCacheList():
results[title] = git
return results
except Exception, e:
Log.Debug('Exception in Migrate/getUASCacheList : ' + str(e))
Log.Critical('Exception in Migrate/getUASCacheList : ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
return ''

# Grap indentifier from plist file and timestamp
Expand Down Expand Up @@ -357,11 +357,11 @@ def getIdentifier(pluginDir):
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish(json.dumps(migratedBundles))
except Exception, e:
Log.Critical('Fatal error happened in migrate: ' + str(e))
Log.Critical('Fatal error happened in migrate: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Fatal error happened in migrate: ' + str(e))
req.finish('Fatal error happened in migrate: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
return req

''' This will return a list of UAS bundle types from the UAS Cache '''
Expand All @@ -373,7 +373,7 @@ def uasTypes(self, req):
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish(json.dumps(Dict['uasTypes']))
except Exception, e:
Log.Critical('Exception in uasTypes: ' + str(e))
Log.Critical('Exception in uasTypes: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
Expand Down Expand Up @@ -408,15 +408,15 @@ def updateUASCache(self, req, cliForce= False):
try:
Core.storage.ensure_dirs(targetDir)
except Exception, e:
errMsg = str(e)
errMsg = str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno)
if 'Errno 13' in errMsg:
errMsg = errMsg + '\n\nLooks like permissions are not correct, cuz we where denied access\n'
errMsg = errMsg + 'to create a needed directory.\n\n'
errMsg = errMsg + 'If running on Linux, you might have to issue:\n'
errMsg = errMsg + 'sudo chown plex:plex ./WebTools.bundle -R\n'
errMsg = errMsg + 'And if on Synology, the command is:\n'
errMsg = errMsg + 'sudo chown plex:users ./WebTools.bundle -R\n'
Log.Critical('Exception in updateUASCache ' + str(e))
Log.Critical('Exception in updateUASCache ' + errMsg)
if not cliForce:
req.clear()
req.set_status(500)
Expand All @@ -429,12 +429,12 @@ def updateUASCache(self, req, cliForce= False):
try:
zipfile = Archive.ZipFromURL(self.UAS_URL+ '/archive/master.zip')
except Exception, e:
Log.Critical('Could not download UAS Repo from GitHub')
Log.Critical('Could not download UAS Repo from GitHub' + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))
if not cliForce:
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Exception in updateUASCache while downloading UAS repo from Github: ' + str(e))
req.finish('Exception in updateUASCache while downloading UAS repo from Github: ' + str(e)+ ' on line {}'.format(sys.exc_info()[-1].tb_lineno))
return req
for filename in zipfile:
# Walk contents of the zip, and extract as needed
Expand All @@ -447,7 +447,7 @@ def updateUASCache(self, req, cliForce= False):
Core.storage.save(path, data)
except Exception, e:
bError = True
Log.Critical("Unexpected Error " + str(e))
Log.Critical("Unexpected Error " + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))
else:
# We got a directory here
Log.Debug(filename.split('/')[-2])
Expand All @@ -459,7 +459,7 @@ def updateUASCache(self, req, cliForce= False):
Core.storage.ensure_dirs(path)
except Exception, e:
bError = True
Log.Critical("Unexpected Error " + str(e))
Log.Critical("Unexpected Error " + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))
# Update the AllBundleInfo as well
pms.updateAllBundleInfoFromUAS()
pms.updateUASTypesCounters()
Expand All @@ -473,12 +473,12 @@ def updateUASCache(self, req, cliForce= False):
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('UASCache is up to date')
except Exception, e:
Log.Critical('Exception in updateUASCache ' + str(e))
Log.Critical('Exception in updateUASCache ' + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))
if not cliForce:
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Exception in updateUASCache ' + str(e))
req.finish('Exception in updateUASCache ' + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))
return req

''' list will return a list of all installed gits from GitHub'''
Expand Down Expand Up @@ -604,7 +604,7 @@ def removeEmptyFolders(path, removeRoot=True):
# Grap file from Github
zipfile = Archive.ZipFromURL(zipPath)
except Exception, e:
Log.Critical('Exception in downloadBundle2tmp while downloading from GitHub: ' + str(e))
Log.Critical('Exception in downloadBundle2tmp while downloading from GitHub: ' + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))
return False
# Create base directory
Core.storage.ensure_dirs(Core.storage.join_path(self.PLUGIN_DIR, bundleName))
Expand Down Expand Up @@ -633,7 +633,7 @@ def removeEmptyFolders(path, removeRoot=True):
Log.Debug('Install is an upgrade')
break
except Exception, e:
Log.Critical('Exception in downloadBundle2tmp while walking the downloaded file to find the plist: ' + str(e))
Log.Critical('Exception in downloadBundle2tmp while walking the downloaded file to find the plist: ' + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))
return False
if bUpgrade:
# Since this is an upgrade, we need to check, if the dev wants us to delete the Cache directory
Expand Down Expand Up @@ -684,7 +684,7 @@ def removeEmptyFolders(path, removeRoot=True):
Core.storage.save(path, data)
except Exception, e:
bError = True
Log.Critical('Exception happend in downloadBundle2tmp: ' + str(e))
Log.Critical('Exception happend in downloadBundle2tmp: ' + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))
else:
if cutStr not in filename:
continue
Expand All @@ -699,7 +699,7 @@ def removeEmptyFolders(path, removeRoot=True):
Core.storage.ensure_dirs(path)
except Exception, e:
bError = True
Log.Critical('Exception happend in downloadBundle2tmp: ' + str(e))
Log.Critical('Exception happend in downloadBundle2tmp: ' + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))

if not bError and bUpgrade:
# Copy files that should be kept between upgrades ("keepFiles")
Expand Down Expand Up @@ -747,7 +747,7 @@ def removeEmptyFolders(path, removeRoot=True):
shutil.move(extractDir, bundleName)
except Exception, e:
bError = True
Log.Critical('Unable to update plugin: ' + str(e))
Log.Critical('Unable to update plugin: ' + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))

# Delete temporary directory
try:
Expand Down Expand Up @@ -776,7 +776,7 @@ def removeEmptyFolders(path, removeRoot=True):
pass
return True
except Exception, e:
Log.Critical('Exception in downloadBundle2tmp: ' + str(e))
Log.Critical('Exception in downloadBundle2tmp: ' + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))
return False

# Starting install main
Expand Down Expand Up @@ -847,11 +847,11 @@ def getLastUpdateTime(self, req, UAS=False, url=''):
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish(str(response))
except Exception, e:
Log.Critical('Fatal error happened in getLastUpdateTime for :' + url + ' was: ' + str(e))
Log.Critical('Fatal error happened in getLastUpdateTime for :' + url + ' was: ' + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Fatal error happened in getLastUpdateTime for :' + url + ' was: ' + str(e))
req.finish('Fatal error happened in getLastUpdateTime for :' + url + ' was: ' + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))

''' Get list of avail bundles in the UAS '''
def getListofBundles(self, req):
Expand Down
28 changes: 14 additions & 14 deletions Contents/Code/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ def __init__(self):
if not os.direxists(self.LOGDIR):
self.LOGDIR = os.path.join(Core.app_support_path, 'Logs')
except Exception, e:
Log.Debug('Fatal error happened in Logs list: ' + str(e))
Log.Debug('Fatal error happened in Logs list: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Fatal error happened in Logs list: ' + str(e))
req.finish('Fatal error happened in Logs list: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
Log.Debug('Log Root dir is: ' + self.LOGDIR)

''' Grap the tornado req for a Get, and process it '''
Expand Down Expand Up @@ -84,11 +84,11 @@ def entry(self, req):
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Entry logged')
except Exception, e:
Log.Debug('Fatal error happened in Logs entry: ' + str(e))
Log.Debug('Fatal error happened in Logs entry: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Fatal error happened in Logs entry: ' + str(e))
req.finish('Fatal error happened in Logs entry: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))

''' This metode will return a list of logfiles. accepts a filter parameter '''
def list(self, req):
Expand All @@ -113,11 +113,11 @@ def list(self, req):
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish(json.dumps(sorted(retFiles)))
except Exception, e:
Log.Debug('Fatal error happened in Logs list: ' + str(e))
Log.Debug('Fatal error happened in Logs list: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Fatal error happened in Logs list: ' + str(e))
req.finish('Fatal error happened in Logs list: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))

''' This will return contents of the logfile as an array. Req. a parameter named fileName '''
def show(self, req):
Expand Down Expand Up @@ -146,11 +146,11 @@ def show(self, req):
req.finish(json.dumps(retFile))
return req
except Exception, e:
Log.Debug('Fatal error happened in Logs show: ' + str(e))
Log.Debug('Fatal error happened in Logs show: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Fatal error happened in Logs show: ' + str(e))
req.finish('Fatal error happened in Logs show: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))

''' This will download a zipfile with the complete log directory. if parameter fileName is specified, only that file will be downloaded, and not zipped'''
def download(self, req):
Expand Down Expand Up @@ -186,11 +186,11 @@ def download(self, req):
os.remove(zipFileName)
return req
except Exception, e:
Log.Debug('Fatal error happened in Logs download: ' + str(e))
Log.Debug('Fatal error happened in Logs download: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Fatal error happened in Logs download: ' + str(e))
req.finish('Fatal error happened in Logs download: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
else:
try:
if 'com.plexapp' in fileName:
Expand All @@ -211,15 +211,15 @@ def download(self, req):
req.finish()
return req
except Exception, e:
Log.Debug('Fatal error happened in Logs download: ' + str(e))
Log.Debug('Fatal error happened in Logs download: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Fatal error happened in Logs download: ' + str(e))
req.finish('Fatal error happened in Logs download: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
except Exception, e:
Log.Debug('Fatal error happened in Logs download: ' + str(e))
Log.Debug('Fatal error happened in Logs download: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Fatal error happened in Logs download: ' + str(e))
req.finish('Fatal error happened in Logs download: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))

Loading

0 comments on commit 95f1370

Please sign in to comment.