Display import errors to user (#27147)

* Display import errors to user

* Refactored

* Refactored

* Refactored

* Fixed quality

* Fixed quality

* Refactored code

* Fixed message

* Refactored code
This commit is contained in:
AsadAzam
2021-04-02 18:53:39 +05:00
committed by GitHub
parent c64d6ab1f0
commit c4da6c1fe4
4 changed files with 41 additions and 12 deletions

View File

@@ -417,7 +417,7 @@ def import_olx(self, user_id, course_key_string, archive_path, archive_name, lan
return User.objects.get(pk=user_id)
except User.DoesNotExist as exc:
with translation_language(language):
self.status.fail(_('Unknown User ID: {0}').format(user_id))
self.status.fail(_('User permission denied.'))
LOGGER.error(f'{log_prefix}: Unknown User: {user_id}')
monitor_import_failure(courselike_key, current_step, exception=exc)
return
@@ -428,7 +428,7 @@ def import_olx(self, user_id, course_key_string, archive_path, archive_name, lan
if not has_access:
message = f'User permission denied: {user.username}'
with translation_language(language):
self.status.fail(_('Permission denied'))
self.status.fail(_('Permission denied. You do not have write access to this course.'))
LOGGER.error(f'{log_prefix}: {message}')
monitor_import_failure(courselike_key, current_step, message=message)
return has_access
@@ -452,7 +452,7 @@ def import_olx(self, user_id, course_key_string, archive_path, archive_name, lan
if not archive_path_exists:
message = f'Uploaded file {archive_path} not found'
with translation_language(language):
self.status.fail(_('Tar file not found'))
self.status.fail(_('Uploaded Tar file not found. Try again.'))
LOGGER.error(f'{log_prefix}: {message}')
monitor_import_failure(courselike_key, current_step, message=message)
return archive_path_exists
@@ -557,7 +557,7 @@ def import_olx(self, user_id, course_key_string, archive_path, archive_name, lan
shutil.rmtree(course_dir)
LOGGER.info(f'{log_prefix}: Temp data cleared')
self.status.fail(str(exception))
self.status.fail(_('An Unknown error occurred during the unpacking step.'))
LOGGER.exception(f'{log_prefix}: Unknown error while unpacking', exc_info=True)
monitor_import_failure(courselike_key, current_step, exception=exception)
return
@@ -601,7 +601,8 @@ def import_olx(self, user_id, course_key_string, archive_path, archive_name, lan
load_error_modules=False,
static_content_store=contentstore(),
target_id=courselike_key,
verbose=True
verbose=True,
status=self.status
)
new_location = courselike_items[0].location
@@ -611,8 +612,9 @@ def import_olx(self, user_id, course_key_string, archive_path, archive_name, lan
set_custom_attribute('course_import_completed', True)
except Exception as exception: # pylint: disable=broad-except
msg = str(exception)
LOGGER.exception(f'{log_prefix}: Unknown error while updating course {msg}')
self.status.fail(msg)
LOGGER.exception(f'{log_prefix}: Unknown error while importing course {msg}')
if self.status.state != UserTaskStatus.FAILED:
self.status.fail(_('Unknown error while importing course.'))
monitor_import_failure(courselike_key, current_step, exception=exception)
finally:
if course_dir.isdir():

View File

@@ -253,6 +253,7 @@ def import_status_handler(request, course_key_string, filename=None):
args = {'course_key_string': course_key_string, 'archive_name': filename}
name = CourseImportTask.generate_name(args)
task_status = UserTaskStatus.objects.filter(name=name)
message = ''
for status_filter in STATUS_FILTERS:
task_status = status_filter().filter_queryset(request, task_status, import_status_handler)
task_status = task_status.order_by('-created').first()
@@ -267,10 +268,13 @@ def import_status_handler(request, course_key_string, filename=None):
status = 4
elif task_status.state in (UserTaskStatus.FAILED, UserTaskStatus.CANCELED):
status = max(-(task_status.completed_steps + 1), -3)
artifact = UserTaskArtifact.objects.filter(name='Error', status=task_status).order_by('-created').first()
if artifact:
message = artifact.text
else:
status = min(task_status.completed_steps + 1, 3)
return JsonResponse({"ImportStatus": status})
return JsonResponse({"ImportStatus": status, "Message": message})
def send_tarball(tarball, size):

View File

@@ -240,7 +240,7 @@ define(
*
* @param {int} [stage=0] Starting stage.
*/
pollStatus: function(stage) {
pollStatus: function(stage, message) {
if (current.state !== STATE.IN_PROGRESS) {
return;
}
@@ -250,13 +250,13 @@ define(
if (current.stage === STAGE.SUCCESS) {
success();
} else if (current.stage < STAGE.UPLOADING) { // Failed
error(gettext('Error importing course'));
error(message || gettext('Error importing course'));
} else { // In progress
updateFeedbackList();
$.getJSON(file.url, function(data) {
timeout.id = setTimeout(function() {
this.pollStatus(data.ImportStatus);
this.pollStatus(data.ImportStatus, data.Message);
}.bind(this), timeout.delay);
}.bind(this));
}
@@ -292,7 +292,7 @@ define(
if (current.stage !== STAGE.UPLOADING) {
current.state = STATE.IN_PROGRESS;
this.pollStatus(current.stage);
this.pollStatus(current.stage, data.Message);
} else {
// An import in the upload stage cannot be resumed
error(gettext('There was an error with the upload'));