From b616e4c584725c099d012920fa3d1fd7dada7bfc Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Thu, 10 Oct 2024 12:42:50 +0200 Subject: [PATCH] fix: fix edge case with pydantic errors this shows: ``` checking registry/poap/calldata-PoapBridge.json... ERROR: Validation error: {'type': 'json_invalid', 'loc': (), 'msg': 'Invalid JSON: expected value at line 1 column 1', 'input': 'Missing/Invalid API Key', 'ctx': {'error': 'expected value at line 1 column 1'}} ``` instead of: ``` checking registry/poap/calldata-PoapBridge.json... Error: Invalid JSON: expected value at line 1 column 1 ``` --- src/erc7730/lint/lint.py | 5 ++++- tests/model/test_model_serialization.py | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/erc7730/lint/lint.py b/src/erc7730/lint/lint.py index 540266d..71be886 100644 --- a/src/erc7730/lint/lint.py +++ b/src/erc7730/lint/lint.py @@ -82,7 +82,10 @@ def lint_file(path: Path, linter: ERC7730Linter, out: OutputAdder) -> None: except ValidationError as e: for ex in e.errors(include_url=False, include_context=True, include_input=True): loc = ex["loc"] - adder.error(title=f"{loc} is invalid", message=ex["msg"]) + if loc == (): + adder.error(title="Validation error", message=str(ex)) + else: + adder.error(title=f"{loc} is invalid", message=ex["msg"]) except Exception as e: # TODO unwrap pydantic validation errors here to provide more user-friendly error messages adder.error(title="Failed to parse descriptor", message=str(e)) diff --git a/tests/model/test_model_serialization.py b/tests/model/test_model_serialization.py index 64a409e..fe5f86e 100644 --- a/tests/model/test_model_serialization.py +++ b/tests/model/test_model_serialization.py @@ -20,6 +20,9 @@ def test_schema(input_file: Path) -> None: """Test model serializes to JSON that matches the schema.""" assert_valid_erc_7730(InputERC7730Descriptor.load(input_file)) +def test_poap() -> None: + """Test model serializes to JSON that matches the schema.""" + InputERC7730Descriptor.load(Path("/home/jnicoulaud/work/ledger/backend/cal/python-erc7730/python-erc7730-1/tests/registries/clear-signing-erc7730-registry/registry/poap/calldata-PoapBridge.json")) @pytest.mark.parametrize("input_file", ERC7730_DESCRIPTORS, ids=path_id) def test_round_trip(input_file: Path) -> None: