AmedeeBulle / pyrak811

RAK811 Python 3 library for Raspberry Pi
Apache License 2.0
50 stars 25 forks source link

Add error messages #4

Closed jezmck closed 5 years ago

jezmck commented 5 years ago

So that e.g. the following can be more descriptive.

Traceback (most recent call last):
  File "/home/pi/lora/lora_node.py", line 20, in <module>
    lora.send('Hellora world')
  File "/usr/local/lib/python3.5/dist-packages/rak811/rak811.py", line 482, in send
    data
  File "/usr/local/lib/python3.5/dist-packages/rak811/rak811.py", line 226, in _send_command
    raise Rak811ResponseError(response[len(RESPONSE_ERROR):])
rak811.rak811.Rak811ResponseError: -5

rak811.rak811.Rak811ResponseError: -5 equates to "CODE_NOT_JOIN", which, while a little unnatural, is more useful.

AmedeeBulle commented 5 years ago

Thank you for the report.

Note that you already can have the error message if you trap the exception yourself -- e.g:

>>> from rak811 import Rak811ResponseError
>>> try:
...     raise Rak811ResponseError(-5)
... except Rak811ResponseError as e:
...     print("[Errno  {}] {}".format(e.errno, e.strerror))
... 
[Errno -5] Not joined

But I will enhance the default message in the backtrace to produce:

>>> from rak811 import Rak811ResponseError
>>> raise Rak811ResponseError(-5)  
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
rak811.rak811.Rak811ResponseError: [Errno -5] Not joined
jezmck commented 5 years ago

Thanks. I'm new to Python and appreciate your advice.

AmedeeBulle commented 5 years ago

0.6.5 has been released on PyPI, just update your library and you will get more descriptive error messages.

sudo pip3 install --upgrade rak811