Clean up and improve error reporting.
authorMatthijs Kooijman <matthijs@stdin.nl>
Wed, 12 Aug 2009 21:09:37 +0000 (23:09 +0200)
committerMatthijs Kooijman <matthijs@stdin.nl>
Thu, 13 Aug 2009 09:58:43 +0000 (11:58 +0200)
This removes some unused stuff and tries to make the error reporting a
bit more clear and concise.

src/main.py

index 8825582a1634161403dce82d97515ddd6c5d80a7..f0953a090ffeae2ae82f342f517f2c2314145c4c 100644 (file)
@@ -46,31 +46,50 @@ def run():
         projects_view = ProjectListView(projects)
         projects_view.run()
     except Exception, e:
-        import appuifw,traceback
-        trace = traceback.extract_tb(sys.exc_info()[2])
-        print e,trace
-        def display(objects):
-            strings=[]
-            for object in objects:
-                strings.append(u'%s'%object)
-            appuifw.selection_list(strings)
+        import appuifw,traceback,os
+        print e
         
-        error_text = unicode(repr(e.args))
+        (type, value, tb) = sys.exc_info()
+        lines = []
+
+        # Create error message
+        for line in traceback.format_exception_only(type, value):
+                lines.append(unicode(line))
+        lines.append("\n")
+
+        # Create stacktrace
+        trace = traceback.extract_tb(tb)
+        trace.reverse()
+
+        basedir = os.path.dirname(__file__) + os.sep
+        for (file, line, func, code) in trace:
+            # Remove the basedir from any filename, since it is not so
+            # interesting but takes up precious space.
+            if file.startswith(basedir):
+                    file = file[len(basedir):]
+            lines.append(u'\n%s:%s\nin %s:\n%s\n' % (file, line, func, code))
+
+        # Create and fill an error dialog
         t = appuifw.Text()
-        for trace_line in trace:
-            formatted_trace_line = u'\nIn %s line %s: %s "%s"'%trace_line
+        for line in lines:
             if logger:
-                logger.log(formatted_trace_line,1)
-            t.add(formatted_trace_line)
-        if logger:
-            logger.log(error_text,1)
-        t.add(error_text)
+                logger.log(line,1)
+            t.add(line)
+
+        # Put the focus back at the top
+        t.set_pos(0)
+
+        # Create a lock to wait on
         lock = e32.Ao_lock()
+
+        # Set up the dialog
         appuifw.app.menu=[(u'Exit', lock.signal)]
     
         appuifw.app.title=u'Error'
         appuifw.app.body=t
         appuifw.app.exit_key_handler=lock.signal
+
+        # Wait until the exit option or button is chosen
         lock.wait()
 
         # Exit app when script returns
@@ -79,6 +98,10 @@ def run():
     if logger:
         logger.close()
 
-run()
+try:
+    run()
+except:
+    import traceback
+    traceback.print_exc()
 
 #tr.stop()