Skip to content

Commit d717af0

Browse files
committed
Tweak error messages
1 parent 51ab22b commit d717af0

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/cattr/converters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ def _structure_list(self, obj, cl):
492492
try:
493493
res.append(handler(e, elem_type))
494494
except Exception as e:
495-
e.__note__ = f"Structuring iterable @ index {ix}"
495+
e.__note__ = f"Structuring {cl} @ index {ix}"
496496
errors.append(e)
497497
finally:
498498
ix += 1

src/cattrs/gen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def make_dict_structure_fn(
340340
lines.append(f"{i}except Exception as e:")
341341
i = f"{i} "
342342
lines.append(
343-
f"{i}e.__note__ = 'Structuring class {cl_name} @ attribute {an}'"
343+
f"{i}e.__note__ = 'Structuring class {cl.__qualname__} @ attribute {an}'"
344344
)
345345
lines.append(f"{i}errors.append(e)")
346346
post_lines.append(f" if errors: raise __c_cve('While structuring {cl.__name__}', errors, __cl)")

tests/test_validation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ class Test:
2525
assert repr(exc.value.exceptions[0]) == repr(
2626
ValueError("invalid literal for int() with base 10: 'a'")
2727
)
28-
assert exc.value.exceptions[0].__note__ == "Structuring class Test @ attribute a"
28+
assert exc.value.exceptions[0].__note__ == "Structuring class test_class_validation.<locals>.Test @ attribute a"
2929

3030
assert repr(exc.value.exceptions[1]) == repr(KeyError("c"))
31-
assert exc.value.exceptions[1].__note__ == "Structuring class Test @ attribute c"
31+
assert exc.value.exceptions[1].__note__ == "Structuring class test_class_validation.<locals>.Test @ attribute c"
3232

3333

3434
def test_list_validation():
@@ -41,12 +41,12 @@ def test_list_validation():
4141
assert repr(exc.value.exceptions[0]) == repr(
4242
ValueError("invalid literal for int() with base 10: 'a'")
4343
)
44-
assert exc.value.exceptions[0].__note__ == "Structuring iterable @ index 2"
44+
assert exc.value.exceptions[0].__note__ == "Structuring typing.List[int] @ index 2"
4545

4646
assert repr(exc.value.exceptions[1]) == repr(
4747
ValueError("invalid literal for int() with base 10: 'c'")
4848
)
49-
assert exc.value.exceptions[1].__note__ == "Structuring iterable @ index 4"
49+
assert exc.value.exceptions[1].__note__ == "Structuring typing.List[int] @ index 4"
5050

5151

5252
def test_mapping_validation():

0 commit comments

Comments
 (0)