Skip to content

Use BluetoothError in _bleio #2311

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 3 commits into from
Nov 21, 2019
Merged

Conversation

tannewt
Copy link
Member

@tannewt tannewt commented Nov 20, 2019

This better differentiates errors than using OSError everywhere.

This better differentiates errors than using OSError everywhere.
Copy link
Collaborator

@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.

This is a very nice cleanup.

One thing to check: do these str/repr/print properly as _bleio.RoleError, etc? These appear to be the first native-module-namespace exceptions we have in the code base.

@tannewt
Copy link
Member Author

tannewt commented Nov 21, 2019

Ok @dhalbert please take another look. Printing now includes the module by overriding the print method.

Adafruit CircuitPython 5.0.0-beta.0-19-g5e857fdb6-dirty on 2019-11-21; Adafruit Feather nRF52840 Express with nRF52840
>>> import _bleio
>>> raise _bleio.BluetoothError("test")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
_bleio.BluetoothError: test
>>> e = _bleio.BluetoothError("test")
>>> str(e)
'test'
>>> repr(e)
"_bleio.BluetoothError('test',)"
>>>

@dhalbert
Copy link
Collaborator

dhalbert commented Nov 21, 2019

I may have asked for too much. Here's CPython and current CircuitPython:
testing.py:

class MyException(Exception):
    pass

CPython:

Python 3.6.8 (default, Oct  7 2019, 12:59:55) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import testing
>>> raise testing.MyException
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
testing.MyException
>>> str(testing.MyException)
"<class 'testing.MyException'>"
>>> str(testing.MyException())
''
>>> repr(testing.MyException())
'MyException()'
>>> 

CircuitPython 5.0.0-beta.0:

>>> import testing
>>> raise testing.MyException
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
MyException: 
>>> str(testing.MyException(3))
'3'
>>> repr(testing.MyException(3))
'MyException(3,)'
>>> 

Copy link
Collaborator

@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.

The print change now matches CPython, but the repr() change does not. Could you undo that? That's the last thing. Thanks!
See
#2311 (comment)

@tannewt
Copy link
Member Author

tannewt commented Nov 21, 2019

Easy enough. Please take another look.

Adafruit CircuitPython 5.0.0-beta.0-20-g521c7531b-dirty on 2019-11-21; Adafruit Feather nRF52840 Express with nRF52840
>>> import _bleio
>>> raise _bleio.BluetoothError("test 2")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
_bleio.BluetoothError: test 2
>>> e = _bleio.BluetoothError("test 2")
>>> str(e)
'test 2'
>>> repr(e)
"BluetoothError('test 2',)"

Copy link
Collaborator

@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 doing this!

@dhalbert dhalbert merged commit 2adecda into adafruit:master Nov 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants