From d1a881e26bb4de0e2238157c3460ce11407f1ad0 Mon Sep 17 00:00:00 2001 From: Chris Lamb Date: Thu, 29 Oct 2009 13:05:51 +0000 Subject: [PATCH] Catch and log all exceptions from top-level dak command. Signed-off-by: Chris Lamb --- dak/dak.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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 ################################################################################ -- 2.39.5