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

Contextualize errors on 'row-number' attr presence

parent 0c0c95c2
......@@ -52,42 +52,42 @@ def extract_source_data(source: ValidataSource, preview_rows_nb=5):
'preview_rows': rows[:preview_rows_nb]}
ERR_CODE_TO_CONTEXT = dict([
# TODO: gets it from spec.json
('duplicate-header', 'head'),
('extra-value', 'body'),
('missing-value', 'body'),
('source-error', 'table'),
('schema-error', 'table'),
('non-matching-header', 'head'),
('blank-row', 'body'),
('blank-header', 'head'),
('enumerable-constraint', 'body'),
('http-error', 'table'),
('scheme-error', 'table'),
('type-or-format-error', 'body'),
('format-error', 'table'),
('extra-header', 'head'),
('pattern-constraint', 'body'),
('required-constraint', 'body'),
('missing-header', 'head'),
('maximum-length-constraint', 'body'),
('maximum-constraint', 'body'),
('minimum-length-constraint', 'body'),
('encoding-error', 'table'),
('io-error', 'table'),
('unique-constraint', 'body'),
('duplicate-row', 'body'),
('minimum-constraint', 'body'),
# TODO: get it from validata_validate
('invalid-column-delimiter', 'table'),
('missing-headers', 'table'),
('wrong-headers-order', 'table'),
('extra-headers', 'table'),
# Custom checks fall in default case: body
])
# ERR_CODE_TO_CONTEXT = dict([
# # TODO: gets it from spec.json
# ('duplicate-header', 'head'),
# ('extra-value', 'body'),
# ('missing-value', 'body'),
# ('source-error', 'table'),
# ('schema-error', 'table'),
# ('non-matching-header', 'head'),
# ('blank-row', 'body'),
# ('blank-header', 'head'),
# ('enumerable-constraint', 'body'),
# ('http-error', 'table'),
# ('scheme-error', 'table'),
# ('type-or-format-error', 'body'),
# ('format-error', 'table'),
# ('extra-header', 'head'),
# ('pattern-constraint', 'body'),
# ('required-constraint', 'body'),
# ('missing-header', 'head'),
# ('maximum-length-constraint', 'body'),
# ('maximum-constraint', 'body'),
# ('minimum-length-constraint', 'body'),
# ('encoding-error', 'table'),
# ('io-error', 'table'),
# ('unique-constraint', 'body'),
# ('duplicate-row', 'body'),
# ('minimum-constraint', 'body'),
# # TODO: get it from validata_validate
# ('invalid-column-delimiter', 'table'),
# ('missing-headers', 'table'),
# ('wrong-headers-order', 'table'),
# ('extra-headers', 'table'),
# # Custom checks fall in default case: body
# ])
ERROR_MESSAGE_FUNC = {
......@@ -133,7 +133,12 @@ def improve_messages(errors, headers, schema):
def contextualize(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):
......
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