Skip to content
Snippets Groups Projects
Verified Commit 1a6a00ab authored by Daniel Hornung's avatar Daniel Hornung
Browse files

ENH: Even better error message.

parent 969f32d4
No related branches found
No related tags found
2 merge requests!128MNT: Added a warning when column metadata is not configured, and a better...,!120XLSX-Konverter: Bessere Fehlermeldung bei inkorrektem Typ in Spalte, zusätzlicher Spalte
Pipeline #57866 passed
...@@ -186,7 +186,8 @@ class XLSXConverter: ...@@ -186,7 +186,8 @@ class XLSXConverter:
self._check_columns(fail_fast=strict) self._check_columns(fail_fast=strict)
except KeyError as e: except KeyError as e:
raise jsonschema.ValidationError(f"Malformed metadata: Cannot parse paths. " raise jsonschema.ValidationError(f"Malformed metadata: Cannot parse paths. "
f"Unknown path: {e}") from e f"Unknown path: '{e.args[1]}' in sheet '{e.args[0]}'."
) from e
self._handled_sheets: set[str] = set() self._handled_sheets: set[str] = set()
self._result: dict = {} self._result: dict = {}
self._errors: dict = {} self._errors: dict = {}
...@@ -270,8 +271,11 @@ class XLSXConverter: ...@@ -270,8 +271,11 @@ class XLSXConverter:
parents[xlsx_utils.p2s(col.path[:-1])] = col.path[:-1] parents[xlsx_utils.p2s(col.path[:-1])] = col.path[:-1]
col_paths.append(col.path) col_paths.append(col.path)
for path in parents.values(): for path in parents.values():
subschema = xlsx_utils.get_subschema(path, self._schema) try:
subschema = xlsx_utils.get_subschema(path, self._schema)
except KeyError as kerr:
kerr.args = (sheetname, *kerr.args)
raise
# Unfortunately, there are a lot of special cases to handle here. # Unfortunately, there are a lot of special cases to handle here.
if subschema.get("type") == "array": if subschema.get("type") == "array":
subschema = subschema["items"] subschema = subschema["items"]
...@@ -544,9 +548,6 @@ def _group_foreign_paths(foreign: list[list], common: list[str]) -> list[SimpleN ...@@ -544,9 +548,6 @@ def _group_foreign_paths(foreign: list[list], common: list[str]) -> list[SimpleN
last_level = len(elem.path) last_level = len(elem.path)
resultlist.append(elem) resultlist.append(elem)
# from IPython import embed
# embed()
if last_level != len(common): if last_level != len(common):
raise ValueError("Foreign keys must cover the complete `common` depth.") raise ValueError("Foreign keys must cover the complete `common` depth.")
return resultlist return resultlist
......
...@@ -153,7 +153,8 @@ def test_error_table(): ...@@ -153,7 +153,8 @@ def test_error_table():
with pytest.raises(jsonschema.ValidationError) as caught: with pytest.raises(jsonschema.ValidationError) as caught:
convert.to_dict(xlsx=rfp("data/simple_data_broken_paths.xlsx"), convert.to_dict(xlsx=rfp("data/simple_data_broken_paths.xlsx"),
schema=rfp("data/simple_schema.json")) schema=rfp("data/simple_schema.json"))
assert "Malformed metadata: Cannot parse paths" in str(caught.value) assert ("Malformed metadata: Cannot parse paths. Unknown path: 'There' in sheet 'Person'."
== str(caught.value))
def test_additional_column(): def test_additional_column():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment