Commit 9d387437 authored by Pierre Dittgen's avatar Pierre Dittgen
Browse files

Emit check error if an unknown custom check is used

parent c425a888
...@@ -5,6 +5,8 @@ from typing import Optional ...@@ -5,6 +5,8 @@ from typing import Optional
import frictionless import frictionless
from validata_core.custom_checks.utils import build_check_error
from .custom_checks import MissingRequiredHeader, available_checks from .custom_checks import MissingRequiredHeader, available_checks
from .error_messages import error_translate from .error_messages import error_translate
from .helpers import ( from .helpers import (
...@@ -108,12 +110,17 @@ def validate(source, schema, **options): ...@@ -108,12 +110,17 @@ def validate(source, schema, **options):
] ]
# Dynamically add custom check based on schema needs # Dynamically add custom check based on schema needs
check_errors = []
for cc_conf in schema.get("custom_checks", []): for cc_conf in schema.get("custom_checks", []):
cc_name = cc_conf["name"] cc_name = cc_conf["name"]
if cc_name in available_checks: if cc_name not in available_checks:
cc_class = available_checks[cc_name] check_errors.append(
cc_descriptor = cc_conf["params"] build_check_error(cc_name, note="custom check inconnu.")
extra_checks.append(cc_class(cc_descriptor)) )
continue
cc_class = available_checks[cc_name]
cc_descriptor = cc_conf["params"]
extra_checks.append(cc_class(cc_descriptor))
# Merge options to pass to frictionless # Merge options to pass to frictionless
validate_options = { validate_options = {
...@@ -159,6 +166,9 @@ def validate(source, schema, **options): ...@@ -159,6 +166,9 @@ def validate(source, schema, **options):
source_header, required_field_names, original_schema source_header, required_field_names, original_schema
) )
) )
if check_errors:
table["errors"].extend(check_errors)
report["valid"] = False
# translate errors # translate errors
report["errors"] = [error_translate(err, schema) for err in report["errors"]] report["errors"] = [error_translate(err, schema) for err in report["errors"]]
......
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