Working on providing good error feedback

svn: r18336
This commit is contained in:
Doug Blank 2011-10-16 17:30:51 +00:00
parent ae5e389bd7
commit d853e2886d
2 changed files with 23 additions and 12 deletions

View File

@ -268,6 +268,7 @@ def send_file(request, filename, mimetype):
def process_action(request, view, handle, action): def process_action(request, view, handle, action):
from webapp.reports import import_file, export_file, download from webapp.reports import import_file, export_file, download
from cli.plug import run_report from cli.plug import run_report
import traceback
db = DbDjango() db = DbDjango()
if view == "report": if view == "report":
if request.user.is_authenticated(): if request.user.is_authenticated():
@ -302,17 +303,24 @@ def process_action(request, view, handle, action):
str(handle), str(handle),
args["iff"])) args["iff"]))
if filename is not None: if filename is not None:
if True: # run in background, with error handling
import threading import threading
def background(): def background():
try: try:
import_file(db, filename, lambda n: n) # callback import_file(db, filename, lambda n: n) # callback
except: except:
message = "import_file failed." message = "import_file failed: " + traceback.format_exc()
request.user.message_set.create(message = message) request.user.message_set.create(message = message)
threading.Thread(target=background).start() threading.Thread(target=background).start()
message = "Your data is now being imported..." message = "Your data is now being imported..."
request.user.message_set.create(message = message) request.user.message_set.create(message = message)
return redirect("/report/") return redirect("/report/")
else:
success = import_file(db, filename, lambda n: n) # callback
if not success:
message = "Failed to load imported."
request.user.message_set.create(message = message)
return redirect("/report/")
else: else:
message = "No filename was provided or found." message = "No filename was provided or found."
request.user.message_set.create(message = message) request.user.message_set.create(message = message)

View File

@ -35,7 +35,9 @@ def import_file(db, filename, callback):
if format == pdata.extension: if format == pdata.extension:
mod = pmgr.load_plugin(pdata) mod = pmgr.load_plugin(pdata)
if not mod: if not mod:
for name, error_tuple in pmgr.get_fail_list(): for item in pmgr.get_fail_list():
name, error_tuple, pdata = item
# (filename, (exception-type, exception, traceback), pdata)
etype, exception, traceback = error_tuple etype, exception, traceback = error_tuple
print "ERROR:", name, exception print "ERROR:", name, exception
return False return False
@ -89,7 +91,8 @@ def export_file(db, filename, callback):
if format == pdata.extension: if format == pdata.extension:
mod = pmgr.load_plugin(pdata) mod = pmgr.load_plugin(pdata)
if not mod: if not mod:
for name, error_tuple in pmgr.get_fail_list(): for item in pmgr.get_fail_list():
name, error_tuple, pdata = item
etype, exception, traceback = error_tuple etype, exception, traceback = error_tuple
print "ERROR:", name, exception print "ERROR:", name, exception
return False return False