Closed
Description
There is currently no portable way of knowing what has gone wrong in case of an error. Perhaps there should be some more specific subclasses of can.CanError for some generally usable exceptions.
If this sounds like a good idea we should start a list of exceptions that could be useful.
- Transmit buffer full
- Unknown channel
- Hardware not connected
- Connection/handle is down
- Bus off
- Drivers could not be loaded
Reacted by Brian Thorne, Thomas Watson, Mathias Giacomuzzi, Felix Divo and Yegor Yefremov
Activity
felixdivo commentedon Jul 18, 2018
An Idea of categorizing this:
hardbyte commentedon Jul 19, 2018
Additionally we should specify how we capture any additional context that the various interfaces might make available. At the very least we usually have an interface specific error code which we should attach to the exceptions in a consistent way.
felixdivo commentedon Jul 19, 2018
Yes, as well as a human readable error message.
felixdivo commentedon Sep 2, 2018
Second Idea of categorizing this:
CanErrorMalformedCanMessageCanBusInitErrorCanOperationErrorCanBufferErrorfelixdivo commentedon Sep 2, 2018
What about errors that are specified by the CAN protocol itself? Are there some scenarios that are considered an error that we need to model with this?
felixdivo commentedon Feb 20, 2019
Can we do this in a minor version bump like 3.2? I think it might be okay, since all exceptions/errors would still inherit from the already existing
CanError, and just be more specific.2 remaining items
marcel-kanter commentedon Apr 30, 2019
I've forked the repo and made a branch.
After having a look into message.py I think the errors for the message may all be handled with the built-in python exceptions, A beginning is in the _check method of the Message object already.
felixdivo commentedon Apr 30, 2019
@marcel-kanter Your structure looks nice, though I do not like the name
CanBackendErrorsince they are all kind of "backend errors". MaybeCanDriverInitError? And the currentCanInitializationErrorrenamed toCanBusInitError?felixdivo commentedon Apr 30, 2019
Do we really want to include this still in 3.2? It could take some time to get it right. (@hardbyte)
marcel-kanter commentedon Apr 30, 2019
To the naming:
We (the contributors of python-can) sit in the middle and have two counterparts: First the user, to whom we expose the front-end - a set of python classes and methods with a certain level of abstraction. Secondly the driver and OS, which we use to provide the functionality and abstraction to the user.
Now call the part that is exposed to the user front-end and the other part the back-end.
The CanBackEndError is related to the backend of the python-can library, more or less the driver/OS level. It may be raised if the driver returns an unexpected value during operation, not only during initialization.
One major reason for this may be a driver version (which the user installed) that does not exactly match the current implementation in python-can. This - i think - may be an even bigger issue on linux mashines where the drivers may be compiled by the user.
Additionally - I wanted to keep the words Driver, OS and Library out of the name.
I'm open for suggestions.
The CanInitializationError will become the CanBusInitError.
marcel-kanter commentedon Apr 30, 2019
I think this may become an bigger change, since all interfaces need to be reviewed at least and some todos spread around...
Maybe for release 4.0?
felixdivo commentedon May 1, 2019
OK, sounds good!
This makes it clear that it is not a problem with loading the driver/whatever/... but instead of creating an instance of it. 👍
felixdivo commentedon May 19, 2019
felixdivo commentedon May 19, 2019
At first this will be developed on branch
unified-exceptions.marcel-kanter commentedon May 24, 2019
Since the exception handling comes with 4.0.0 release i removed the deprecations and the Python 2.7 support already. Who wants to integrate this already, have a look at Commit
@marcel-kanter@3fea588
felixdivo commentedon Jun 23, 2019
@marcel-kanter They are already removed on develop because of #594, #595, #596 and #597.