From: W. Trevor King Date: Mon, 10 May 2010 15:35:03 +0000 (-0400) Subject: Don't crash when Command._run() raises an uncaught Exception. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e5dcfdd61750e1cbf6f3ac337c0915039ec74641;p=hooke.git Don't crash when Command._run() raises an uncaught Exception. Just print the traceback and move on. This gives the user time to exit gracefully (saving playlists etc.). --- diff --git a/hooke/command.py b/hooke/command.py index 60e7233..adb3818 100644 --- a/hooke/command.py +++ b/hooke/command.py @@ -3,7 +3,9 @@ """ import Queue as queue +import sys import textwrap +import traceback class CommandExit (Exception): @@ -16,6 +18,13 @@ class Success (CommandExit): class Failure (CommandExit): pass +class UncaughtException (Failure): + def __init__(self, exception): + super(UncaughtException, self).__init__(exception) + self.exception = exception + self.exc_string = traceback.format_exc() + sys.exc_clear() + class Command (object): """One-line command description here. @@ -62,6 +71,11 @@ class Command (object): outqueue.put(str(e)) outqueue.put(e) return 1 + except Exception, e: + x = UncaughtException(e) + outqueue.put(x.exc_string) + outqueue.put(x) + return 1 outqueue.put(e) return 0