From 0076d6a64d9b64d9ccd76f6e2d840f571e4d3b27 Mon Sep 17 00:00:00 2001 From: Adam Palay Date: Tue, 30 Jul 2013 13:20:18 -0400 Subject: [PATCH] fix error handling distinguish logged error and instructor-facing error --- lms/djangoapps/instructor/views.py | 52 +++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/lms/djangoapps/instructor/views.py b/lms/djangoapps/instructor/views.py index 77150c9f71..d356687000 100644 --- a/lms/djangoapps/instructor/views.py +++ b/lms/djangoapps/instructor/views.py @@ -310,7 +310,9 @@ def instructor_dashboard(request, course_id): "Delete student state for module" in action or "Rescore student's problem submission" in action): # get the form data - unique_student_identifier = request.POST.get('unique_student_identifier', '') + unique_student_identifier = request.POST.get( + 'unique_student_identifier', '' + ) problem_urlname = request.POST.get('problem_for_student', '') module_state_key = get_module_url(problem_urlname) # try to uniquely id student by email address or username @@ -327,22 +329,35 @@ def instructor_dashboard(request, course_id): ) msg += "Found module. " except StudentModule.DoesNotExist as err: - msg += "Couldn't find module with that urlname. " - msg += "Error: {0} ".format(err.message) - log.exception(msg) + error_msg = "Couldn't find module with that urlname: {0}. ".format( + problem_urlname + ) + msg += "" + error_msg + "({0}) ".format(err) + "" + log.debug(error_msg) if student_module is not None: if "Delete student state for module" in action: # delete the state try: student_module.delete() - msg += "Deleted student module state for %s!" % module_state_key - event = {"problem": problem_url, "student": unique_student_identifier, "course": course_id} - track.views.server_track(request, "delete-student-module-state", event, page="idashboard") + msg += "Deleted student module state for {0}!".format(module_state_key) + event = { + "problem": problem_url, + "student": unique_student_identifier, + "course": course_id + } + track.views.server_track( + request, + "delete-student-module-state", + event, + page="idashboard" + ) except Exception as err: - msg += "Failed to delete module state for {0}/{1} ".format(unique_student_identifier, problem_urlname) - msg += "Error: {0} ".format(err.message) - log.exception(msg) + error_msg = "Failed to delete module state for {0}/{1}. ".format( + unique_student_identifier, problem_urlname + ) + msg += "" + error_msg + "({0}) ".format(err) + "" + log.exception(error_msg) elif "Reset student's attempts" in action: # modify the problem's state try: @@ -363,9 +378,11 @@ def instructor_dashboard(request, course_id): track.views.server_track(request, "reset-student-attempts", event, page="idashboard") msg += "Module state successfully reset!" except Exception as err: - msg += "Couldn't reset module state. " - msg += "Error: {0} ".format(err.message) - log.exception(msg) + error_msg = "Couldn't reset module state for {0}/{1}. ".format( + unique_student_identifier, problem_urlname + ) + msg += "" + error_msg + "({0}) ".format(err) + "" + log.exception(error_msg) else: # "Rescore student's problem submission" case try: @@ -375,8 +392,13 @@ def instructor_dashboard(request, course_id): else: track.views.server_track(request, "rescore-student-submission", {"problem": module_state_key, "student": unique_student_identifier, "course": course_id}, page="idashboard") except Exception as err: - msg += 'Failed to create a background task for rescoring "{0}": {1}.'.format(module_state_key, err.message) - log.exception(msg) + msg += 'Failed to create a background task for rescoring "{0}": {1}.'.format( + module_state_key, err.message + ) + log.exception("Encountered exception from rescore: student '{0}' problem '{1}'".format( + unique_student_identifier, module_state_key + ) + ) elif "Get link to student's progress page" in action: unique_student_identifier = request.POST.get('unique_student_identifier', '')