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
Add local error class. #2
Conversation
Requiring users to catch a raw Exception instead of providing our own error class is bad, it encourages bad coding habits and forces users to write code that can hide real bugs. Instead, define a local subclass of Exception, and throw that instead.
is this done or do you want to finish mirroring C errors first? |
i suggest to finish mirroring @Ferroin |
I intend to finish mirroring the C errors first. I should hopefully have an initial version doing that some time later today. |
This provides Python Exception subclasses equivalent to each of the errors defined by the libsensors API so that they can be individually caught. It also proivdes a function to handle raising the appropriate error based on the return value of the function that caused it. Tracebacks with this are not quite as nice as they were, adding an extra function to the end, but there is unfortunately no way that I know of to avoid this that is compatible with both Python 2 and Python 3.
Updated, with some minimal testing. I've added appropriate secondary inheritance for exceptions based on what they are as well, so you can do sane things like trying to catch |
I accidentally forgot to test paroj#2 properly beyond the first commit. As a result, I accidentally introduced both a Python 2 compatibility issue (`PermissionsError` was not introduced until a recent version of Python 3), and multiple typos that cause the module to fail to load regardless of Python version. This fixes both.
I accidentally forgot to test #2 properly beyond the first commit. As a result, I accidentally introduced both a Python 2 compatibility issue (`PermissionsError` was not introduced until a recent version of Python 3), and multiple typos that cause the module to fail to load regardless of Python version. This fixes both.
Requiring users to catch a raw Exception instead of providing our own error class is bad, it encourages bad coding habits and forces users to write code that can hide real bugs.
Instead, define a local subclass of Exception, and throw that instead.