From: Chris Lamb Date: Thu, 29 Oct 2009 13:05:51 +0000 (+0000) Subject: Catch and log all exceptions from top-level dak command. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d1a881e26bb4de0e2238157c3460ce11407f1ad0;p=dak Catch and log all exceptions from top-level dak command. Signed-off-by: Chris Lamb --- diff --git a/dak/dak.py b/dak/dak.py index 052f3b3e..448c137f 100755 --- a/dak/dak.py +++ b/dak/dak.py @@ -34,8 +34,12 @@ G{importgraph} ################################################################################ import sys +import traceback import daklib.utils +from daklib.daklog import Logger +from daklib.config import Config + ################################################################################ def init(): @@ -152,6 +156,8 @@ Available commands:""" def main(): """Launch dak functionality.""" + logger = Logger(Config(), 'dak top-level') + functionality = init() modules = [ command for (command, _) in functionality ] @@ -189,7 +195,17 @@ def main(): # Invoke the module module = __import__(cmdname.replace("-","_")) - module.main() + try: + module.main() + except KeyboardInterrupt: + msg = 'KeyboardInterrupt caught; exiting' + print msg + logger.log([msg]) + sys.exit(1) + except: + for line in traceback.format_exc().split('\n')[:-1]: + logger.log(['exception', line]) + raise ################################################################################