Skip to content
Snippets Groups Projects
Unverified Commit 8023bbc1 authored by Awais Jibran's avatar Awais Jibran Committed by GitHub
Browse files

Log Errors + Warnings. (#27210)

parent 89014ca6
Branches
Tags
No related merge requests found
...@@ -30,14 +30,12 @@ def send_task_complete_email(self, task_name, task_state_text, dest_addr, detail ...@@ -30,14 +30,12 @@ def send_task_complete_email(self, task_name, task_state_text, dest_addr, detail
context = { context = {
'task_name': task_name, 'task_name': task_name,
'task_status': task_state_text, 'task_status': task_state_text,
'detail_url': detail_url 'detail_url': detail_url,
'olx_validation_errors': False
} }
if olx_validation_text: if olx_validation_text:
try: try:
olx_validations = json.loads(olx_validation_text) context['olx_validation_errors'] = json.loads(olx_validation_text)
context['olx_validation_errors'] = True
context['error_summary'] = olx_validations.get('error_summary')
context['error_report'] = olx_validations.get('error_report')
except ValueError: # includes simplejson.decoder.JSONDecodeError except ValueError: # includes simplejson.decoder.JSONDecodeError
LOGGER.error(f'Unable to parse CourseOlx validation text: {olx_validation_text}') LOGGER.error(f'Unable to parse CourseOlx validation text: {olx_validation_text}')
......
...@@ -684,21 +684,31 @@ def validate_course_olx(courselike_key, course_dir, status): ...@@ -684,21 +684,31 @@ def validate_course_olx(courselike_key, course_dir, status):
LOGGER.exception(f'{log_prefix}: CourseOlx Could not be validated') LOGGER.exception(f'{log_prefix}: CourseOlx Could not be validated')
return olx_is_valid return olx_is_valid
log_errors = len(errorstore.errors) > 0
if log_errors:
log_errors_to_artifact(errorstore, status)
has_errors = errorstore.return_error(ErrorLevel.ERROR.value) has_errors = errorstore.return_error(ErrorLevel.ERROR.value)
if not has_errors: if not has_errors:
return olx_is_valid return olx_is_valid
errorstore.errors = [error for error in errorstore.errors if error.level_val == ErrorLevel.ERROR.value]
error_summary = report_error_summary(errorstore)
error_report = report_errors(errorstore)
message = json.dumps({
'error_summary': error_summary,
'error_report': error_report,
})
UserTaskArtifact.objects.create(status=status, name='OLX_VALIDATION_ERROR', text=message)
LOGGER.error(f'{log_prefix}: CourseOlx validation failed') LOGGER.error(f'{log_prefix}: CourseOlx validation failed')
# TODO: Do not fail the task until we have some data about kinds of # TODO: Do not fail the task until we have some data about kinds of
# olx validation failures. TNL-8151 # olx validation failures. TNL-8151
return olx_is_valid return olx_is_valid
def log_errors_to_artifact(errorstore, status):
"""Log errors as a task artifact."""
def get_error_by_type(error_type):
return [error for error in error_report if error.startswith(error_type)]
error_summary = report_error_summary(errorstore)
error_report = report_errors(errorstore)
message = json.dumps({
'summary': error_summary,
'errors': get_error_by_type(ErrorLevel.ERROR.name),
'warnings': get_error_by_type(ErrorLevel.WARNING.name),
})
UserTaskArtifact.objects.create(status=status, name='OLX_VALIDATION_ERROR', text=message)
...@@ -12,13 +12,16 @@ ${_("Your {task_name} task has completed with the status '{task_status}'. Sign i ...@@ -12,13 +12,16 @@ ${_("Your {task_name} task has completed with the status '{task_status}'. Sign i
% if olx_validation_errors: % if olx_validation_errors:
${_("Here are some validation errors we found with your course content.")} ${_("Here are some validations we found with your course content.")}
${_("Errors:")}
% for error in error_report: % for error in olx_validation_errors.get('errors'):
${error} * ${error}
% endfor % endfor
% else: ${_("Warnings:")}
% for warning in olx_validation_errors.get('warnings'):
* ${warning}
% endfor
% endif % endif
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