From 760d5d7adfa573dd7f52277e14f85e5b0efa5b54 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Wed, 12 Aug 2009 23:09:37 +0200 Subject: [PATCH 1/1] Clean up and improve error reporting. This removes some unused stuff and tries to make the error reporting a bit more clear and concise. --- src/main.py | 57 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/src/main.py b/src/main.py index 8825582..f0953a0 100644 --- a/src/main.py +++ b/src/main.py @@ -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() -- 2.30.2