chiark / gitweb /
Don't use generic Exception raises
authorDaniel Martí <mvdan@mvdan.cc>
Mon, 7 Jul 2014 13:41:32 +0000 (15:41 +0200)
committerDaniel Martí <mvdan@mvdan.cc>
Mon, 7 Jul 2014 13:41:50 +0000 (15:41 +0200)
That hides bugs, since all exceptions (including bugs that cause raises that
weren't our doing) fall under the "Exception" except

fdroidserver/build.py
fdroidserver/checkupdates.py
fdroidserver/common.py
fdroidserver/install.py
fdroidserver/verify.py

index 9139a361346ec0ceb92af662cea4ee51f685a754..87eaa9c9a37094f44627240bc2dec245367dd00a 100644 (file)
@@ -34,7 +34,7 @@ import logging
 
 import common
 import metadata
-from common import BuildException, VCSException, FDroidPopen, SilentPopen
+from common import FDroidException, BuildException, VCSException, FDroidPopen, SilentPopen
 
 try:
     import paramiko
@@ -991,7 +991,7 @@ def main():
             len(app['Repo Type']) > 0 and len(app['builds']) > 0]
 
     if len(apps) == 0:
-        raise Exception("No apps to process.")
+        raise FDroidException("No apps to process.")
 
     if options.latest:
         for app in apps:
index 23d5b778abbd3b6dc5b00b47a05230400c77ebf7..44919e20cdfabc618f62b6e0c7f7f7625d9adc33 100644 (file)
@@ -32,7 +32,7 @@ import logging
 
 import common
 import metadata
-from common import VCSException
+from common import VCSException, FDroidException
 from metadata import MetaDataException
 
 
@@ -44,7 +44,7 @@ def check_http(app):
     try:
 
         if 'Update Check Data' not in app:
-            raise Exception('Missing Update Check Data')
+            raise FDroidException('Missing Update Check Data')
 
         urlcode, codeex, urlver, verex = app['Update Check Data'].split('|')
 
@@ -57,7 +57,7 @@ def check_http(app):
 
             m = re.search(codeex, page)
             if not m:
-                raise Exception("No RE match for version code")
+                raise FDroidException("No RE match for version code")
             vercode = m.group(1)
 
         version = "??"
@@ -70,12 +70,12 @@ def check_http(app):
 
             m = re.search(verex, page)
             if not m:
-                raise Exception("No RE match for version")
+                raise FDroidException("No RE match for version")
             version = m.group(1)
 
         return (version, vercode)
 
-    except Exception:
+    except FDroidException:
         msg = "Could not complete http check for app {0} due to unknown error: {1}".format(app['id'], traceback.format_exc())
         return (None, msg)
 
index 93f811874a9e97752e7a0204d34aeb01281c7942..ce3acc12fa3a21bb0ac9d68ca7c9c297b55350c0 100644 (file)
@@ -259,9 +259,9 @@ def read_app_args(args, allapps, allow_vercodes=False):
         for p in vercodes:
             if p not in allids:
                 logging.critical("No such package: %s" % p)
-        raise Exception("Found invalid app ids in arguments")
+        raise FDroidException("Found invalid app ids in arguments")
     if not apps:
-        raise Exception("No packages specified")
+        raise FDroidException("No packages specified")
 
     error = False
     for app in apps:
@@ -277,7 +277,7 @@ def read_app_args(args, allapps, allow_vercodes=False):
                     logging.critical("No such vercode %s for app %s" % (v, app['id']))
 
     if error:
-        raise Exception("Found invalid vercodes for some apps")
+        raise FDroidException("Found invalid vercodes for some apps")
 
     return apps
 
@@ -299,7 +299,7 @@ def apknameinfo(filename):
     try:
         result = (m.group(1), m.group(2))
     except AttributeError:
-        raise Exception("Invalid apk name: %s" % filename)
+        raise FDroidException("Invalid apk name: %s" % filename)
     return result
 
 
index 673efd6f1efd8b8b286e4988dddf47749cb359ea..338ddf9647226a0a5a200b201ccf5f2abf2a3bc2 100644 (file)
@@ -25,7 +25,7 @@ from optparse import OptionParser, OptionError
 import logging
 
 import common
-from common import FDroidPopen
+from common import FDroidPopen, FDroidException
 
 options = None
 config = None
@@ -34,7 +34,7 @@ config = None
 def devices():
     p = FDroidPopen([config['adb'], "devices"])
     if p.returncode != 0:
-        raise Exception("An error occured when finding devices: %s" % p.output)
+        raise FDroidException("An error occured when finding devices: %s" % p.output)
     lines = p.output.splitlines()
     if lines[0].startswith('* daemon not running'):
         lines = lines[2:]
@@ -85,7 +85,7 @@ def main():
 
         for appid, apk in apks.iteritems():
             if not apk:
-                raise Exception("No signed apk available for %s" % appid)
+                raise FDroidException("No signed apk available for %s" % appid)
 
     else:
 
@@ -96,7 +96,7 @@ def main():
         # Get device list each time to avoid device not found errors
         devs = devices()
         if not devs:
-            raise Exception("No attached devices found")
+            raise FDroidException("No attached devices found")
         logging.info("Installing %s..." % apk)
         for dev in devs:
             logging.info("Installing %s on %s..." % (apk, dev))
@@ -111,7 +111,7 @@ def main():
             if fail == "INSTALL_FAILED_ALREADY_EXISTS":
                 logging.warn("%s is already installed on %s." % (apk, dev))
             else:
-                raise Exception("Failed to install %s on %s: %s" % (
+                raise FDroidException("Failed to install %s on %s: %s" % (
                     apk, dev, fail))
 
     logging.info("\nFinished")
index 417f2c51ce9437a0be192316dea8b601e54e17c0..60983febf39c15182b39719d5e5ccda3ada82b9c 100644 (file)
@@ -26,7 +26,7 @@ from optparse import OptionParser
 import logging
 
 import common
-from common import FDroidPopen
+from common import FDroidPopen, FDroidException
 
 options = None
 config = None
@@ -82,7 +82,7 @@ def main():
             logging.info("...retrieving " + url)
             p = FDroidPopen(['wget', url], cwd=tmp_dir)
             if p.returncode != 0:
-                raise Exception("Failed to get " + apkfilename)
+                raise FDroidException("Failed to get " + apkfilename)
 
             thisdir = os.path.join(tmp_dir, 'this_apk')
             thatdir = os.path.join(tmp_dir, 'that_apk')
@@ -94,21 +94,21 @@ def main():
             if subprocess.call(['jar', 'xf',
                                 os.path.join("..", "..", unsigned_dir, apkfilename)],
                                cwd=thisdir) != 0:
-                raise Exception("Failed to unpack local build of " + apkfilename)
+                raise FDroidException("Failed to unpack local build of " + apkfilename)
             if subprocess.call(['jar', 'xf',
                                 os.path.join("..", "..", remoteapk)],
                                cwd=thatdir) != 0:
-                raise Exception("Failed to unpack remote build of " + apkfilename)
+                raise FDroidException("Failed to unpack remote build of " + apkfilename)
 
             p = FDroidPopen(['diff', '-r', 'this_apk', 'that_apk'], cwd=tmp_dir)
             lines = p.output.splitlines()
             if len(lines) != 1 or 'META-INF' not in lines[0]:
-                raise Exception("Unexpected diff output - " + p.output)
+                raise FDroidException("Unexpected diff output - " + p.output)
 
             logging.info("...successfully verified")
             verified += 1
 
-        except Exception, e:
+        except FDroidException, e:
             logging.info("...NOT verified - {0}".format(e))
             notverified += 1