[Dextrose] [PATCH sugar-toolkit] More robust handling of unhandled exceptions

Aleksey Lim alsroot at member.fsf.org
Mon Jan 24 05:57:50 EST 2011


---
 src/sugar/feedback.py |   24 +++++++++++++++---------
 1 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/sugar/feedback.py b/src/sugar/feedback.py
index 56dacab..770b7a7 100644
--- a/src/sugar/feedback.py
+++ b/src/sugar/feedback.py
@@ -79,6 +79,11 @@ def _send(activity_id, log_path):
             log_path if need_log else '')
 
 
+def _format_exception(exctype, value, tb):
+    import traceback
+    return ''.join(traceback.format_exception(exctype, value, tb))
+
+
 def _excepthook(exctype, value, tb):
     global _log_formatter
 
@@ -89,15 +94,16 @@ def _excepthook(exctype, value, tb):
             from IPython.ultraTB import AutoFormattedTB
             formatter = AutoFormattedTB(mode='Verbose', color_scheme='NoColor')
             _log_formatter = formatter.text
-        except ImportError:
-            import traceback
-            _log_formatter = \
-                    lambda * args: ''.join(traceback.format_exception(*args))
-
-    message = _log_formatter(exctype, value, tb)
-    logging.error(message)
-
-    trigger('unhandled_exception', need_log=True)
+        except BaseException:
+            _log_formatter = _format_exception
+
+    try:
+        message = _log_formatter(exctype, value, tb)
+        logging.error(message)
+        trigger('unhandled_exception', need_log=True)
+    except BaseException, error:
+        print >>sys.stderr, 'Unhandled %r while processing: %r %r' % \
+                (error, exctype, value)
 
 
 sys.excepthook = _excepthook
-- 
1.7.3.4



More information about the Dextrose mailing list