Skip to content

preserve last exception when things are going wrong #124

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
Jan 9, 2023

Conversation

jepler
Copy link
Contributor

@jepler jepler commented Jan 9, 2023

CircuitPython 8 supports exception chaining, so that the original problem can be shown. Here's how it looks on desktop python3:

Traceback (most recent call last):
  File "/home/jepler/src/bundle/libraries/helpers/requests/adafruit_requests.py", line 527, in _get_socket
    sock.connect((connect_host, port))
ConnectionRefusedError: [Errno 111] Connection refused

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jepler/src/bundle/libraries/helpers/requests/adafruit_requests.py", line 721, in get
    return self.request("GET", url, **kw)
  File "/home/jepler/src/bundle/libraries/helpers/requests/adafruit_requests.py", line 661, in request
    socket = self._get_socket(host, port, proto, timeout=timeout)
  File "/home/jepler/src/bundle/libraries/helpers/requests/adafruit_requests.py", line 508, in _get_socket
    raise RuntimeError("Sending request failed") from last_exc
RuntimeError: Sending request failed

Before, just the second block would be shown, and it would be hidden that the underlying cause was "connection refused".

CircuitPython 8 supports exception chaining, so that the original
problem can be shown. Here's how it looks on desktop python3:
```
Traceback (most recent call last):
  File "/home/jepler/src/bundle/libraries/helpers/requests/adafruit_requests.py", line 527, in _get_socket
    sock.connect((connect_host, port))
ConnectionRefusedError: [Errno 111] Connection refused

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jepler/src/bundle/libraries/helpers/requests/adafruit_requests.py", line 721, in get
    return self.request("GET", url, **kw)
  File "/home/jepler/src/bundle/libraries/helpers/requests/adafruit_requests.py", line 661, in request
    socket = self._get_socket(host, port, proto, timeout=timeout)
  File "/home/jepler/src/bundle/libraries/helpers/requests/adafruit_requests.py", line 508, in _get_socket
    raise RuntimeError("Sending request failed") from last_exc
RuntimeError: Sending request failed
```
Copy link
Contributor

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this diagnostic help!

@dhalbert dhalbert merged commit 203d0b1 into main Jan 9, 2023
@dhalbert dhalbert deleted the chain-exception-when-fail branch January 9, 2023 16:14
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jan 10, 2023
Updating https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k to 1.13.1 from 1.13.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_Wiznet5k#80 from BiffoBear/dhcp_error_handling

Updating https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad to 1.17.0 from 1.16.8:
  > Merge pull request adafruit/Adafruit_CircuitPython_ImageLoad#63 from FoamyGuy/png_typing_and_example
  > Add .venv to .gitignore
  > Update .pylintrc for v2.15.5
  > Fix release CI files
  > Update pylint to 2.15.5
  > Updated pylint version to 2.13.0
  > Switching to composite actions

Updating https://github.com/adafruit/Adafruit_CircuitPython_Motor to 3.4.6 from 3.4.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_Motor#67 from tekktrik/pwmout-fix
  > Add .venv to .gitignore
  > Update .pylintrc for v2.15.5
  > Fix release CI files
  > Update pylint to 2.15.5
  > Updated pylint version to 2.13.0
  > Switching to composite actions

Updating https://github.com/adafruit/Adafruit_CircuitPython_Requests to 1.12.12 from 1.12.11:
  > Merge pull request adafruit/Adafruit_CircuitPython_Requests#124 from adafruit/chain-exception-when-fail
  > Add .venv to .gitignore

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Updated download stats for the libraries
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