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
This commit is contained in:
Daniel Martí 2014-07-07 15:41:32 +02:00
parent b56360512c
commit ff06694adc
5 changed files with 22 additions and 22 deletions

View 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:

View 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)

View 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

View 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")

View 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