-
Notifications
You must be signed in to change notification settings - Fork 659
General exception handling (+ changes to the ixxat interface) #562
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
General exception handling (+ changes to the ixxat interface) #562
Conversation
Started to use the new exception types.
…d. The method returns True on success and False on timeout, if the user wanted an timeout.
|
Checks fail, since the ixxat interface cannot be loaded on the test environment. |
|
I will create a new branch for this and point the PR to it. (Done) |
Codecov Report
@@ Coverage Diff @@
## unified-exceptions #562 +/- ##
======================================================
+ Coverage 64.03% 64.04% +<.01%
======================================================
Files 63 64 +1
Lines 5700 5715 +15
======================================================
+ Hits 3650 3660 +10
- Misses 2050 2055 +5 |
hardbyte
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for taking up the challenge.
can/exceptions.py
Outdated
| class CanOperationError(CanError): | ||
| """ Indicates an error while operation. | ||
| """ | ||
| pass No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: newline at end of file please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oups. Will be fixed.
| # Real return value is an unsigned long | ||
| result = ctypes.c_ulong(result).value | ||
|
|
||
| #print(hex(result), function) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove
can/interfaces/ixxat/canlib.py
Outdated
|
|
||
| """ | ||
| Sends a message on the bus. The interface may buffer the message. | ||
| returns True on success or when timeout is None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the sphinx syntax we use elsewhere in the code base.
See for example https://github.com/hardbyte/python-can/blob/develop/can/interfaces/socketcan/socketcan.py#L573-L596
can/interfaces/ixxat/canlib.py
Outdated
| Sends a message on the bus. The interface may buffer the message. | ||
| returns True on success or when timeout is None | ||
| returns False on timeout (when timeout is not None) | ||
| raises CanOperationError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest we raise an exception on timeout rather return a boolean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Thats a good point. Maybe our way thinking about Exceptions differs a bit. This method is a good example for "fine-adjusting" the handling/rasising of exceptions.
We have two cases: With or without timeout
First without timeout: Thats easy. The user don't want a timeout, so any timeout is a case that should not happen -> exceptional behavior which needs special treatment.
Second with timeout: Thats the point. The user wanted a timeout, so he/she accepts any timeout (maybe don't cares about it - recovering from a fault situation might be a situation were this mades much sense. the fault may still be present and the other node not reachable). So is an timeout an exceptional behavior? Not really. (But i still need to clearify if an timeout may occur because of exceptional behavior of the driver. Then this can get complicated.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In any case the behavior should be consistent between interfaces. If we change to return a boolean instead of raising an exception then other interfaces must change too.
My original intention was that if a timeout is specified, the developer really wants to make sure the message is sent or queued successfully. If not then something is wrong and the program may be stopped or it can try to retransmit later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll stick to the more pythonic raise-an-exception way.
BUT. Should we generally use the built-in TimeoutError for timeouts or sub-class CanError?
I prefer the built-in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would there be an issue inheriting from both? I agree that our specific exception e.g. CanBusWriteTimeout should inherit from TimeoutError and I imagine it should work also inheriting from our generic CanError exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there would be no problem. But i would call this class CanTimeoutError and use it generally for timeout errors, not only for send.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand I don’t think the OSErrors are supposed to be used for other than pure system level errors.
“Raised when a system function timed out at the system level. Corresponds to errno ETIMEDOUT.”
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oki. I had a look into other python packages and the common unterstanding is like christian said it. They dervie their own TimeoutError.
So we'll get an CanTimeoutError
|
|
||
| class SoftwareTestCase(unittest.TestCase): | ||
| """ | ||
| Test cases that test the software only and do not rely on an existing/connected hardware. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do they require any driver software to be installed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually they rely on the ixxat driver installed on the maschine. Currently I'll skip the tests, if they can't be loaded (ImportError).
Still looking for a good and simple way for testing as much as possible without any driver.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could have a look at test_systec.py, which uses unittest.mock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They have linux drivers for x86 and AMD64 on their website.
I contacted HMS (Ixxat is a part of them) and got an beta driver for ARM64, I'm going to test them on the weekend on my ODROID.
Then we may get linux working support too.
Win32 and cygwin will both load "vcimpl.dll". Added comments.
|
We should also consider a way to document this. Maybe like this hierarchy, along with the autodoc classes added to |
| class CanBackEndError(CanError): | ||
| """ Indicates an error related to the backend (e.g. driver/OS/library) | ||
| Examples: | ||
| - A call to a library function results in an unexpected return value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add the return code as a parameter, which is None if not explicitly set? Also applies to CanInitializationError. This way, we could unify it a little bit, and it would be opt-in for interfaces where it would be helpful to have the error codes as a user.
Is there an easy and fast way to build the doc locally? When I try python setup.py build_sphinx I get an error that sphinx misses some a packet programoutput |
|
I never heard of that error. It just works on my machine. Could you post the part of the output that indicates the problem? |
|
I got this output, but then I found that the missing extension is an addon to sphinx, with this addon, building works: Warning: 'classifiers' should be a list, got type 'tuple' Extension error: I'll change the version to 4.0.0-dev0 |
marcel-kanter
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to PEP440 and the implementation in setuptools, the normalized version should be 4.0.0.dev0 (with the 0 at the end).
Change version to 4.0.0.dev0 Fix classifiers in setup.py, it should be a list.
hardbyte
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we still have work to do with regard to common attributes our exceptions could expose but this is a great start
hardbyte
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good start, we need to sort out the optional/required exception attributes next but we can merge this into develop
|
Erm sorry that was weird, ignore my double review. Glitch in the intewebs |
A starting point for the unification of the exception handling.
Includes some improvements for the ixxat interface (the improvements use the new exceptions).
Please pull this into new branch, to keep the develop working until this work is applied to all the interfaces/classes/etc...
Closes #560
Addresses #356