Skip to content

Improve error message when a schema is not JSON valid. #343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2025

Conversation

dgarros
Copy link
Contributor

@dgarros dgarros commented Apr 4, 2025

This PR aim to improve the error message reported by the SDK when the schema received from the server is not JSON valid.

Currently a json.decoder.JSONDecodeError exception will be raised but it doesn't contain enough information

2025-03-21T13:56:10.519447Z [error    ] Failed to execute generator: Expecting value: line 1 column 1 (char 0) [prefect.flow_runs] routing_key=check.generator.run
[...]
  File "/opt/infrahub/git/182ed5b8-d9c2-e54a-3ee3-106550e9b385/commits/f42cdfbfa634e470425650887aa4acf70cbc9ec2/infrahub_edge/models.py", line 2639, in get_and_save_infrahub_node
    node = await client.get(kind=kind, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/source/community/python_sdk/infrahub_sdk/client.py", line 467, in get
    schema = await self.schema.get(kind=kind, branch=branch)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/source/community/python_sdk/infrahub_sdk/schema/__init__.py", line 190, in get
    self.cache[branch] = await self.fetch(branch=branch, timeout=timeout)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/source/community/python_sdk/infrahub_sdk/schema/__init__.py", line 405, in fetch
    data: MutableMapping[str, Any] = response.json()
                                     ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpx/_models.py", line 766, in json
    return jsonlib.loads(self.content, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/json/decoder.py", line 338, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/json/decoder.py", line 356, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Copy link

codecov bot commented Apr 4, 2025

Codecov Report

Attention: Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
infrahub_sdk/schema/__init__.py 60.00% 2 Missing ⚠️
@@            Coverage Diff             @@
##           stable     #343      +/-   ##
==========================================
- Coverage   72.45%   72.44%   -0.02%     
==========================================
  Files          91       91              
  Lines        8165     8169       +4     
  Branches     1572     1572              
==========================================
+ Hits         5916     5918       +2     
- Misses       1838     1840       +2     
  Partials      411      411              
Flag Coverage Δ
integration-tests 22.27% <40.00%> (+<0.01%) ⬆️
python-3.10 46.55% <40.00%> (-0.02%) ⬇️
python-3.11 46.55% <40.00%> (-0.02%) ⬇️
python-3.12 46.52% <40.00%> (-0.02%) ⬇️
python-3.13 46.52% <40.00%> (-0.04%) ⬇️
python-3.9 44.90% <40.00%> (+0.01%) ⬆️
python-filler-3.12 25.08% <20.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/schema/__init__.py 69.81% <60.00%> (-0.26%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dgarros dgarros requested a review from a team April 4, 2025 08:42
@dgarros dgarros marked this pull request as ready for review April 4, 2025 12:19
@dgarros dgarros merged commit 37d0d00 into stable Apr 4, 2025
18 checks passed
@dgarros dgarros deleted the dga-20250404-fix-http branch April 4, 2025 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants