Skip to content

Throw friendly error when device is disconnected - #373

Merged
dwalton76 merged 3 commits into
developfrom
friendly-disconnect-errors
Sep 29, 2017
Merged

dwalton76 merged 3 commits into
developfrom
friendly-disconnect-errors

Conversation

@WasabiFan

Copy link
Copy Markdown
Member

No description provided.

Comment thread ev3dev/core.py Outdated
raise ValueError("The given speed value was out of range. Max speed: +/-" + str(max_speed)) from driver_error
raise ValueError("One or more arguments were out of range or invalid") from driver_error
elif driver_error.errno == errno.ENODEV:
raise Exception("The device is no longer connected") from driver_error

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why 'no longer'? Do we know it was ever connected?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Currently, if it was never connected, the connected property is false and we throw an exception at a higher level. There's an if somewhere around here which handles that case.

@dwalton76 dwalton76 Sep 23, 2017 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How about:

raise Exception("%s is no longer connected" % self) from driver_error

that way the exception has the __str__ of the device that was disconnected

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I haven't paid attention to how inheritance works in Python... Will that have the expected behavior? I know that __class__ is the type the method was defined in and not the runtime type of the enclosing object.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The Device class has a __str__ that will be used to determine what to print whenver you have to print the object in a string

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The question I was asking was a technical one about the language. I'll figure it out and update as needed.

@dwalton76
dwalton76 self-requested a review September 23, 2017 11:31
Comment thread ev3dev/core.py Outdated
attribute.seek(0)

try:
if None == attribute:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we follow PEP-8? If so we should do if attribute is None here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, this is existing code. I'll update it.

@dwalton76 dwalton76 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good

@dwalton76
dwalton76 merged commit 3171043 into develop Sep 29, 2017
@WasabiFan
WasabiFan deleted the friendly-disconnect-errors branch February 14, 2018 15:58
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.

3 participants