Commit 9476961b by Victor Shnayder

Prettier error display

* Log formatted traceback string instead of exc_info tuple itself
* display as a list
parent 943195bc
import logging import logging
import sys import sys
import traceback
from collections import namedtuple from collections import namedtuple
...@@ -14,21 +15,21 @@ def in_exception_handler(): ...@@ -14,21 +15,21 @@ def in_exception_handler():
def make_error_tracker(): def make_error_tracker():
'''Return an ErrorLog (named tuple), with fields (tracker, errors), where '''Return an ErrorLog (named tuple), with fields (tracker, errors), where
the logger appends a tuple (message, exc_info=None) the logger appends a tuple (message, exception_str) to the errors on every
to the errors on every call. call. exception_str is in the format returned by traceback.format_exception.
error_list is a simple list. If the caller messes with it, info error_list is a simple list. If the caller modifies it, info
will be lost. will be lost.
''' '''
errors = [] errors = []
def error_tracker(msg): def error_tracker(msg):
'''Log errors''' '''Log errors'''
exc_info = None exc_str = ''
if in_exception_handler(): if in_exception_handler():
exc_info = sys.exc_info() exc_str = ''.join(traceback.format_exception(*sys.exc_info()))
errors.append((msg, exc_info)) errors.append((msg, exc_str))
return ErrorLog(error_tracker, errors) return ErrorLog(error_tracker, errors)
......
...@@ -51,7 +51,13 @@ ...@@ -51,7 +51,13 @@
% if course_errors is not UNDEFINED: % if course_errors is not UNDEFINED:
<h2>Course errors</h2> <h2>Course errors</h2>
<div id="course-errors"> <div id="course-errors">
${course_errors} <ul>
% for (msg, err) in course_errors:
<li>${msg}
<ul><li><pre>${err}</pre></li></ul>
</li>
% endfor
</ul>
</div> </div>
% endif % endif
</section> </section>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment