Raise meaningful exception for Vector when a channel is not available#355
Raise meaningful exception for Vector when a channel is not available#355christiansandberg merged 3 commits intodevelopfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #355 +/- ##
===========================================
- Coverage 58.6% 58.55% -0.05%
===========================================
Files 54 54
Lines 4215 4218 +3
===========================================
Hits 2470 2470
- Misses 1745 1748 +3
Continue to review full report at Codecov.
|
|
I'm not sure this is the complete solution. This solution only detects when the channel is configured correctly in the Vector API, but its hardware is not present. If the user specifies an invalid channel (negative or too big) or invalid app_name, the xlGetApplConfig raises an exception with XL_ERROR. In fact I'm not really sure I like the error handling in general in this library. Having a generic CanError and VectorError (and whatever other bus types have) with strings as errors is kind of useless when you want to be able to tell the user to correctly configure the Vector stuff, that their interface isn't plugged in, or even something like "transmit queue full". It also makes changing library versions or bus types not really possible. I haven't looked into it in enough detail to see what changing error behavior would entail or how that would look, but I think it needs serious consideration. Sorry for this rant, I'm not too sure where to put it. For reference, here's the code I put in my program to detect the important cases when connecting: |
|
I didn't want to use Regarding the general error handling in python-can I agree that it can be improved a lot. Right now there isn't any portable way to know what's wrong. Perhaps there should be more general subclasses of |
|
For the record, I am not insisting you simulate the XL_ERR_HW_NOT_PRESENT. If you prefer to raise a CanError for now, I think that's okay because I can still differentiate that. But that should be reconsidered with future error handling improvements. |
Fixes #353.