Skip to content
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

fix: fix JSONDEcodeError exception #200

Merged
merged 3 commits into from
Jan 10, 2025

Conversation

etiennevincent
Copy link
Contributor

Description

When trying to delete a folder, the exception raised is not json.JSONDEcodeError but requests.exceptions.JSONDECodeError.

JSONDecodeError                           Traceback (most recent call last)
File ~/.local/lib/python3.11/site-packages/requests/models.py:974, in Response.json(self, **kwargs)
    973 try:
--> 974     return complexjson.loads(self.text, **kwargs)
    975 except JSONDecodeError as e:
    976     # Catch JSON-related errors and raise as requests.JSONDecodeError
    977     # This aliases json.JSONDecodeError and simplejson.JSONDecodeError

File /usr/local/lib/python3.11/json/__init__.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    343 if (cls is None and object_hook is None and
    344         parse_int is None and parse_float is None and
    345         parse_constant is None and object_pairs_hook is None and not kw):
--> 346     return _default_decoder.decode(s)
    347 if cls is None:

File /usr/local/lib/python3.11/json/decoder.py:337, in JSONDecoder.decode(self, s, _w)
    333 """Return the Python representation of ``s`` (a ``str`` instance
    334 containing a JSON document).
    335 
    336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    338 end = _w(s, end).end()

File /usr/local/lib/python3.11/json/decoder.py:355, in JSONDecoder.raw_decode(self, s, idx)
    354 except StopIteration as err:
--> 355     raise JSONDecodeError("Expecting value", s, err.value) from None
    356 return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

JSONDecodeError                           Traceback (most recent call last)
Cell In[97], line 1
----> 1 a = c.DELETE(path)

File ~/.local/lib/python3.11/site-packages/grafana_client/client.py:183, in GrafanaClient.__getattr__.<locals>.__request_runner(url, json, data, headers, accept_empty_json)
    181     return r.text
    182 try:
--> 183     return r.json()
    184 except JSONDecodeError:
    185     if accept_empty_json and r.text == "":

File ~/.local/lib/python3.11/site-packages/requests/models.py:978, in Response.json(self, **kwargs)
    974     return complexjson.loads(self.text, **kwargs)
    975 except JSONDecodeError as e:
    976     # Catch JSON-related errors and raise as requests.JSONDecodeError
    977     # This aliases json.JSONDecodeError and simplejson.JSONDecodeError
--> 978     raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Checklist

  • [ x] The patch has appropriate test coverage
  • [ x] The patch follows the style guidelines of this project
  • [ x] The patch has appropriate comments, particularly in hard-to-understand areas
  • [ x] The documentation was updated corresponding to the patch
  • [ x] I have performed a self-review of this patch

When trying to delete a folder, the exception raised is not `json.JSONDEcodeError` but `requests.exceptions.JSONDECodeError`
@etiennevincent etiennevincent requested a review from amotl as a code owner January 6, 2025 20:58
Copy link

codecov bot commented Jan 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.29%. Comparing base (c6c799b) to head (4e94ca4).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #200   +/-   ##
=======================================
  Coverage   92.29%   92.29%           
=======================================
  Files          27       27           
  Lines        1816     1816           
=======================================
  Hits         1676     1676           
  Misses        140      140           
Flag Coverage Δ
unittests 92.29% <100.00%> (ø)

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@amotl
Copy link
Contributor

amotl commented Jan 10, 2025

Hi. Thanks for the patch. Do you have any idea why CI fails on one of the PyPy runs?

Edit: Fixed by re-running, so it apparently just was a hiccup. Thanks!

@amotl amotl merged commit bead01b into grafana-toolbox:main Jan 10, 2025
5 of 6 checks passed
@etiennevincent etiennevincent deleted the patch-1 branch January 10, 2025 22:53
@etiennevincent
Copy link
Contributor Author

Thanks @amotl for merging! Can we create a tag please?

@amotl
Copy link
Contributor

amotl commented Jan 10, 2025

Absolutely, I will run a release right away.

@amotl
Copy link
Contributor

amotl commented Jan 10, 2025

Version 4.2.1 has been released. Thanks again.

@etiennevincent
Copy link
Contributor Author

Sorry @amotl, another one for you: #202
This repo does not use requests but niquests, my bad!

@amotl
Copy link
Contributor

amotl commented Jan 10, 2025

Thank you @etiennevincent, and sorry for not spotting this issue right away.
I've just released version 4.2.2, including your fix. Thanks again.

@amotl
Copy link
Contributor

amotl commented Jan 10, 2025

Do you think those errors on the CI job of a downstream project could be related?

They suddenly started happening, while there haven't been any problems before.

NB: In order not to expand the conversation on this PR about a different topic, please respond on the issue above, if you have anything to contribute to resolve this problem. Thank you!

@amotl
Copy link
Contributor

amotl commented Jan 11, 2025

Nevermind, this patch fixes it. Sorry for the noise.

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