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

Better display check-errors

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