From ff06694adc525a6251a2a06464e46383962bd330 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Mart=C3=AD?= Date: Mon, 7 Jul 2014 15:41:32 +0200 Subject: [PATCH] Don't use generic Exception raises That hides bugs, since all exceptions (including bugs that cause raises that weren't our doing) fall under the "Exception" except --- fdroidserver/build.py | 4 ++-- fdroidserver/checkupdates.py | 10 +++++----- fdroidserver/common.py | 8 ++++---- fdroidserver/install.py | 10 +++++----- fdroidserver/verify.py | 12 ++++++------ 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/fdroidserver/build.py b/fdroidserver/build.py index 9139a361..87eaa9c9 100644 --- a/fdroidserver/build.py +++ b/fdroidserver/build.py @@ -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: diff --git a/fdroidserver/checkupdates.py b/fdroidserver/checkupdates.py index 23d5b778..44919e20 100644 --- a/fdroidserver/checkupdates.py +++ b/fdroidserver/checkupdates.py @@ -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) diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 93f81187..ce3acc12 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -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 diff --git a/fdroidserver/install.py b/fdroidserver/install.py index 673efd6f..338ddf96 100644 --- a/fdroidserver/install.py +++ b/fdroidserver/install.py @@ -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") diff --git a/fdroidserver/verify.py b/fdroidserver/verify.py index 417f2c51..60983feb 100644 --- a/fdroidserver/verify.py +++ b/fdroidserver/verify.py @@ -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 -- 2.30.2