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

Exception handling tries to use function.__name__ #16

Closed
dannystaple opened this issue May 8, 2022 · 1 comment · Fixed by #17
Closed

Exception handling tries to use function.__name__ #16

dannystaple opened this issue May 8, 2022 · 1 comment · Fixed by #17

Comments

@dannystaple
Copy link
Contributor

While testing AirLift code, I must have triggered the RuntimeError in WSGIApp.__call__. Which lead to this error:

Traceback (most recent call last):
  File "code.py", line 1, in <module>
  File "counting.py", line 23, in <module>
  File "robot_wifi.py", line 52, in start_wifi_server
  File "adafruit_esp32spi/adafruit_esp32spi_wsgiserver.py", line 105, in update_poll
  File "adafruit_wsgi/wsgi_app.py", line 74, in __call__
AttributeError: 'function' object has no attribute '__name__'

CircuitPython does not implement the function.__name__ magic. The following demonstrates this:

Adafruit CircuitPython 7.3.0-beta.2 on 2022-04-27; Raspberry Pi Pico with rp2040
>>> def a():
...     return 1
...
...
>>> a.__name__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute '__name__'

This is different from CPython:

Python 3.7.4 (v3.7.4:e09359112e, Jul  8 2019, 14:54:52) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def a():
...   return 1
... 
>>> a.__name__
'a'

The current exception handler looks like:

                raise RuntimeError(
                    "Proper HTTP response return not given for request handler '{}'".format(
                        route["func"].__name__
                    )
                ) from err

I recommend maybe a getattr with a default?

>>> getattr('a', '__name__', '')
''

Which means where it is available it will format in the name, otherwise it's empty.

@dannystaple
Copy link
Contributor Author

Or perhaps use the route name...

dannystaple added a commit to dannystaple/Adafruit_CircuitPython_WSGI that referenced this issue May 8, 2022
tekktrik added a commit that referenced this issue May 21, 2022
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 a pull request may close this issue.

1 participant