Skip to content

No exception raised on Message creation failure #148

@radiocane

Description

@radiocane

Maybe it's just me, but I think it's wrong not to raise an exception when Message creations fails. For example:

bruno@jeeg:~$ python
Python 2.7.11+ (default, Apr 17 2016, 14:00:29) 
[GCC 5.3.1 20160413] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import can
>>> a = can.Message(arbitration_id=0x300, is_remote_frame=0, dlc=8, data=u'01234567', extended_id=False)
>>>

This looks like everything went fine, but it didn't. Just trying to print the message will give some misleading hint:

>>> a
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/mnt/storage/extern/python-can/can/message.py", line 88, in __repr__
    data = ["{:#02x}".format(byte) for byte in self.data]
AttributeError: 'Message' object has no attribute 'data'

I would rather prefer something like:

>>> a = can.Message(arbitration_id=0x300, is_remote_frame=0, dlc=8, data=u'01234567', extended_id=False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/mnt/storage/extern/python-can/can/message.py", line 34, in __init__
    raise TypeError(err)
TypeError: Couldn't create message from 01234567 (<type 'unicode'>)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions