Commit fb072b77 authored by Pierre Dittgen's avatar Pierre Dittgen
Browse files

Better display check-errors

parent 03615c93
......@@ -6,7 +6,7 @@ import logging
from collections import Counter
from datetime import datetime
from pathlib import Path
from typing import Any, Dict, List
from typing import Any, Dict, Iterable, List
from urllib.parse import urlencode, urljoin
import frictionless
......@@ -351,6 +351,16 @@ def get_badge_url_and_message(badge):
return (badge_url, msg)
def iter_task_errors(validata_core_report, *, error_code: str) -> Iterable[dict]:
if not validata_core_report["tasks"]:
return
yield from [
err
for err in validata_core_report["tasks"][0]["errors"]
if err["code"] == error_code
]
def validate(schema_instance: SchemaInstance, validata_resource: ValidataResource):
"""Validate source and display report."""
......@@ -390,17 +400,26 @@ def validate(schema_instance: SchemaInstance, validata_resource: ValidataResourc
if badge_stats:
badge_url, badge_msg = get_badge_url_and_message(badge_stats)
# Non table errors
if validata_core_report["errors"]:
non_table_error = validata_core_report["errors"][0]
msg = non_table_error.message
log.error(msg)
ui_error_msg = f"Une erreur est survenue durant la validation : {msg}"
if msg.startswith("The validation task has an error"):
ui_error_msg = (
"La validation ne peut s'effectuer sur ce fichier, "
"celui-ci n'est pas compatible avec le schéma."
)
check_errors = list(
iter_task_errors(validata_core_report, error_code="check-error")
)
if check_errors:
ui_error_msg = (
'Erreur de schéma dans la section "custom_checks" : '
f"{check_errors[0]['note']} Validation annulée."
)
flash_error(ui_error_msg)
return redirect(
compute_validation_form_url(schema_instance.request_parameters())
)
task_errors = list(iter_task_errors(validata_core_report, error_code="task-error"))
if task_errors:
log.error(task_errors[0]["message"])
ui_error_msg = (
"Une erreur est survenue durant la validation,"
" consultez notre FAQ pour plus d'informations."
)
flash_error(ui_error_msg)
return redirect(
compute_validation_form_url(schema_instance.request_parameters())
......
Supports Markdown
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