Skip to content

Commit

Permalink
fix: fix edge case with pydantic errors
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
jnicoulaud-ledger committed Oct 10, 2024
1 parent 14b2eea commit b616e4c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/erc7730/lint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 3 additions & 0 deletions tests/model/test_model_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b616e4c

Please sign in to comment.