Skip to content
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

Merged
merged 3 commits into from Nov 14, 2018
Merged

Add local error class. #2

merged 3 commits into from Nov 14, 2018

Conversation

Ferroin
Copy link
Contributor

@Ferroin Ferroin commented Nov 13, 2018

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.

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.
@paroj
Copy link
Owner

paroj commented Nov 13, 2018

is this done or do you want to finish mirroring C errors first?

@ilyam8
Copy link

ilyam8 commented Nov 14, 2018

i suggest to finish mirroring @Ferroin

@Ferroin
Copy link
Contributor Author

Ferroin commented Nov 14, 2018

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.
@Ferroin
Copy link
Contributor Author

Ferroin commented Nov 14, 2018

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 PermissionsError and have it work as expected.

sensors.py Outdated Show resolved Hide resolved
@paroj paroj merged commit 2fa16fe into paroj:master Nov 14, 2018
Ferroin added a commit to Ferroin/sensors.py that referenced this pull request Nov 20, 2018
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.
paroj pushed a commit that referenced this pull request Nov 20, 2018
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.
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.

None yet

3 participants