Commit 485adb55 authored by Pierre Dittgen's avatar Pierre Dittgen
Browse files

Contextualize errors on 'row-number' attr presence

parent 0c0c95c2
...@@ -52,42 +52,42 @@ def extract_source_data(source: ValidataSource, preview_rows_nb=5): ...@@ -52,42 +52,42 @@ def extract_source_data(source: ValidataSource, preview_rows_nb=5):
'preview_rows': rows[:preview_rows_nb]} 'preview_rows': rows[:preview_rows_nb]}
ERR_CODE_TO_CONTEXT = dict([ # ERR_CODE_TO_CONTEXT = dict([
# TODO: gets it from spec.json # # TODO: gets it from spec.json
('duplicate-header', 'head'), # ('duplicate-header', 'head'),
('extra-value', 'body'), # ('extra-value', 'body'),
('missing-value', 'body'), # ('missing-value', 'body'),
('source-error', 'table'), # ('source-error', 'table'),
('schema-error', 'table'), # ('schema-error', 'table'),
('non-matching-header', 'head'), # ('non-matching-header', 'head'),
('blank-row', 'body'), # ('blank-row', 'body'),
('blank-header', 'head'), # ('blank-header', 'head'),
('enumerable-constraint', 'body'), # ('enumerable-constraint', 'body'),
('http-error', 'table'), # ('http-error', 'table'),
('scheme-error', 'table'), # ('scheme-error', 'table'),
('type-or-format-error', 'body'), # ('type-or-format-error', 'body'),
('format-error', 'table'), # ('format-error', 'table'),
('extra-header', 'head'), # ('extra-header', 'head'),
('pattern-constraint', 'body'), # ('pattern-constraint', 'body'),
('required-constraint', 'body'), # ('required-constraint', 'body'),
('missing-header', 'head'), # ('missing-header', 'head'),
('maximum-length-constraint', 'body'), # ('maximum-length-constraint', 'body'),
('maximum-constraint', 'body'), # ('maximum-constraint', 'body'),
('minimum-length-constraint', 'body'), # ('minimum-length-constraint', 'body'),
('encoding-error', 'table'), # ('encoding-error', 'table'),
('io-error', 'table'), # ('io-error', 'table'),
('unique-constraint', 'body'), # ('unique-constraint', 'body'),
('duplicate-row', 'body'), # ('duplicate-row', 'body'),
('minimum-constraint', 'body'), # ('minimum-constraint', 'body'),
# TODO: get it from validata_validate # # TODO: get it from validata_validate
('invalid-column-delimiter', 'table'), # ('invalid-column-delimiter', 'table'),
('missing-headers', 'table'), # ('missing-headers', 'table'),
('wrong-headers-order', 'table'), # ('wrong-headers-order', 'table'),
('extra-headers', 'table'), # ('extra-headers', 'table'),
# Custom checks fall in default case: body # # Custom checks fall in default case: body
]) # ])
ERROR_MESSAGE_FUNC = { ERROR_MESSAGE_FUNC = {
...@@ -133,7 +133,12 @@ def improve_messages(errors, headers, schema): ...@@ -133,7 +133,12 @@ def improve_messages(errors, headers, schema):
def contextualize(errors): def contextualize(errors):
""" add context to errors """ """ add context to errors """
return [{**err, 'context': ERR_CODE_TO_CONTEXT.get(err['code'], 'body')} for err in errors] def add_context(err):
""" Adds context info based on row-nb presence """
context = 'body' if 'row-number' in err else 'table'
return {**err, 'context': context}
return list(map(add_context, errors))
def create_validata_report(goodtables_report, schema): def create_validata_report(goodtables_report, schema):
......
Markdown is supported
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