mystic-ai / pipeline

Pipeline is an open source python SDK for building AI/ML workflows
https://www.mystic.ai
Apache License 2.0
127 stars 22 forks source link

Handle JSONDecodeError in get_response_error_dict() #380

Closed the-crypt-keeper closed 7 months ago

the-crypt-keeper commented 8 months ago

Pull request outline

If any endpoint returns 502, the error message looks like a dog's breakfast and doesn't actually say 502 anywhere:

Expecting value: line 2 column 1 (char 1)
Traceback (most recent call last):
  File "/home/user/.local/lib/python3.10/site-packages/pipeline/console/__init__.py", line 64, in _run
    execute_cli(parser)
  File "/home/user/.local/lib/python3.10/site-packages/pipeline/console/__init__.py", line 54, in execute_cli
    selected_func(parsed_args)
  File "/home/user/.local/lib/python3.10/site-packages/pipeline/console/container/__init__.py", line 291, in _push_container
    registry_info = http.get(endpoint="/v4/registry")
  File "/home/user/.local/lib/python3.10/site-packages/pipeline/cloud/http.py", line 40, in wrapper
    get_response_error_dict(e),
  File "/home/user/.local/lib/python3.10/site-packages/pipeline/cloud/http.py", line 27, in get_response_error_dict
    return {"message": "Something went wrong.", "response_json": e.response.json()}
  File "/home/user/.local/lib/python3.10/site-packages/httpx/_models.py", line 762, in json
    return jsonlib.loads(self.content, **kwargs)
  File "/usr/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 1)

After this PR, the JSONDecoderError is caught and handled correctly:

Pipeline 15:19:21 - [ERROR]: {'message': 'Something went wrong.', 'response': <Response [502 Bad Gateway]>}
Traceback (most recent call last):
  File "/home/user/.local/lib/python3.10/site-packages/pipeline/console/__init__.py", line 64, in _run
    execute_cli(parser)
  File "/home/user/.local/lib/python3.10/site-packages/pipeline/console/__init__.py", line 54, in execute_cli
    selected_func(parsed_args)
  File "/home/user/.local/lib/python3.10/site-packages/pipeline/console/container/__init__.py", line 290, in _push_container
    registry_info = http.get(endpoint="/v4/registry")
  File "/home/user/.local/lib/python3.10/site-packages/pipeline/cloud/http.py", line 39, in wrapper
    response.raise_for_status()
  File "/home/user/.local/lib/python3.10/site-packages/httpx/_models.py", line 759, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Server error '502 Bad Gateway' for url 'https://mystic.ai/v4/registry'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/502

Checklist:

Added:

Changed:

Removed:

Related issues:

none


rossgray commented 8 months ago

Thanks for the PR @the-crypt-keeper . I agree we need to improve the error handling in several places. I've actually merged a PR to fix the above issue and improve the error reporting in several places: https://github.com/mystic-ai/pipeline/pull/384 so hopefully this should address this PR too. Let me know if not