From e5dcfdd61750e1cbf6f3ac337c0915039ec74641 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 10 May 2010 11:35:03 -0400 Subject: [PATCH] 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.). --- hooke/command.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 -- 2.26.2