Skip to content

Add custom exception classes instead of using plain error types. #9

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

Merged
merged 1 commit into from
Dec 31, 2019

Conversation

Ferroin
Copy link
Contributor

@Ferroin Ferroin commented Oct 8, 2019

This adds custom exception classes so that users do not have to match on generic exception types in code that uses this module.

The new custom classes are structured so that existing code that is matching on the generic exception types will still work, and so that there's a primary exception type that can be matched on to catch all
errors specific to this module.


Fixes: #8

This is minimally tested right now (using flake8 to check that there are no syntax errors or other obvious problems with the changes). I intend to test it further, but won't be able to until at least this evening, or possibly tomorrow evening. I'll comment here again when I've finished proper testing.

This adds custom exception classes so that users do not have to match on
generic exception types in code that uses this module.

The new custom classes are structured so that existing code that is
matching on the generic exception types will still work, and so that
there's a primary exception type that can be matched on to catch all
errors specific to this module.
@ladyada ladyada requested a review from a team October 8, 2019 18:52
@ladyada
Copy link
Member

ladyada commented Oct 8, 2019

looks good! please let us know when you've tested this with hardware :)

@Ferroin
Copy link
Contributor Author

Ferroin commented Oct 11, 2019

looks good! please let us know when you've tested this with hardware :)

I don't have actual hardware to test with, as mentioned in the issue this was prompted by review of a plugin for Netdata that uses this module to collect data from the hardware (relevant discussion that prompted this starts at netdata/netdata#7024 (comment)).

However, I have now (now that I finally got time to do so) tested it using Linux's i2c-stub driver to simulate an AM2320 (configured to just return a static value for the temperature and humidity), and nothing appears to behave any different with or without the change (except of course for the type of the exceptions that get raised, and the memory usage (marginally higher, empty classes aren't free, but they're not particularly expensive either)). I can't really confirm the I2C read error behavior this way though (at least, I'm pretty sure I can't, I don't think I can get the i2c-stub driver to simulate a read error), but the CRC mismatch and connection failure errors work correctly.

@ladyada
Copy link
Member

ladyada commented Oct 11, 2019

ooh ok - we'll get to reviewing this later, hardware's tricky so we like to always test with physsical hardware :)

Copy link

@jepler jepler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look reasonable and should not affect existing code

@ladyada ladyada merged commit cbc1863 into adafruit:master Dec 31, 2019
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jan 23, 2020
Updating https://github.com/adafruit/Adafruit_CircuitPython_AM2320 to 1.1.4 from 1.1.3:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_AM2320#9 from Ferroin/master
  > Merge pull request adafruit/Adafruit_CircuitPython_AM2320#11 from adafruit/dherrada-patch-1
  > Update README.rst
  > Merge pull request adafruit/Adafruit_CircuitPython_AM2320#10 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_DS1307 to 2.0.2 from 2.0.1:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_DS1307#15 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_DS1307#14 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_DS3231 to 2.2.2 from 2.2.1:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_DS3231#21 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_FocalTouch to 1.1.7 from 1.1.6:
  > update pylint examples directive

Updating https://github.com/adafruit/Adafruit_CircuitPython_FRAM to 1.2.5 from 1.2.4:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_FRAM#14 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_FRAM#11 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_FXAS21002C to 2.0.2 from 2.0.1:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_FXAS21002C#12 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_FXAS21002C#11 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_FXOS8700 to 2.0.2 from 2.0.1:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_FXOS8700#15 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_FXOS8700#14 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_HTU21D to 0.9.1 from 0.9.0:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_HTU21D#7 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_HTU21D#6 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_INA260 to 1.1.4 from 1.1.3:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_INA260#8 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_INA260#7 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_IS31FL3731 to 2.5.3 from 2.5.2:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_IS31FL3731#21 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_IS31FL3731#20 from makermelissa/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_LSM9DS0 to 2.1.3 from 2.1.2:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_LSM9DS0#16 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_LSM9DS0#15 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_LSM9DS1 to 2.0.6 from 2.0.5:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_LSM9DS1#18 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_MatrixKeypad to 1.1.5 from 1.1.4:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_MatrixKeypad#8 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_MatrixKeypad#7 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_MAX7219 to 1.2.3 from 1.2.2:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_MAX7219#23 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_MCP4725 to 1.2.1 from 1.2.0:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_MCP4725#11 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_MCP4725#10 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_MCP9808 to 3.2.4 from 3.2.3:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_MCP9808#20 from signalmeister/signalmeister-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_MCP9808#22 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_MCP9808#21 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_MLX90393 to 1.3.2 from 1.3.1:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_MLX90393#13 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_MLX90393#12 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_MMA8451 to 1.2.5 from 1.2.4:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_MMA8451#8 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_MMA8451#7 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_MPL3115A2 to 1.1.6 from 1.1.5:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_MPL3115A2#10 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_MPL3115A2#9 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_PCD8544 to 1.1.2 from 1.1.1:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_PCD8544#9 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_PCF8523 to 1.3.1 from 1.3.0:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_PCF8523#14 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_PCF8523#13 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_Pixie to 1.1.6 from 1.1.5:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_Pixie#14 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_Pixie#13 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_PyPortal to 3.1.6 from 3.1.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_PyPortal#60 from cogliano/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_RA8875 to 3.0.1 from 3.0.0:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_RA8875#17 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_RFM69 to 1.3.1 from 1.3.0:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_RFM69#21 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_SD to 3.2.6 from 3.2.5:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_SD#30 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_SI4713 to 1.1.5 from 1.1.4:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_SI4713#11 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_SI4713#10 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_SI5351 to 1.1.5 from 1.1.4:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_SI5351#10 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_SI5351#9 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_SI7021 to 3.1.5 from 3.1.4:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_SI7021#15 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_SI7021#14 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_TCA9548A to 0.2.2 from 0.2.1:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_TCA9548A#14 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_TCA9548A#13 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_TCS34725 to 3.2.4 from 3.2.3:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_TCS34725#25 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_TLC5947 to 1.2.4 from 1.2.3:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_TLC5947#18 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_TLC5947#17 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_TMP007 to 2.0.1 from 2.0.0:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_TMP007#7 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_TMP007#6 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_TSL2561 to 3.2.3 from 3.2.2:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_TSL2561#28 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_TSL2561#27 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_VC0706 to 4.0.4 from 4.0.3:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_VC0706#11 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_VC0706#10 from kattni/update-example-pi
  > Merge pull request adafruit/Adafruit_CircuitPython_VC0706#9 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_VL53L0X to 3.1.7 from 3.1.6:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_VL53L0X#13 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_VL6180X to 1.1.5 from 1.1.4:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_VL6180X#10 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_VL6180X#9 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_OneWire to 1.1.4 from 1.1.3:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_OneWire#17 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_RTTTL to 2.3.2 from 2.3.1:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_RTTTL#18 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_Waveform to 1.2.6 from 1.2.5:
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_Waveform#15 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Added the following libraries: Adafruit_CircuitPython_BLE_Apple_Media, Adafruit_CircuitPython_NTP
@jerryneedell
Copy link
Contributor

jerryneedell commented Apr 16, 2020

just an FYI -- I've reproduced this on a Grand Central and a Teensy 4.0.. It looks like this was never tested on hardware, correct? Did it ever work?
Added more info in #15 -- works on RPi 4 -- will continue in the issue

@jerryneedell jerryneedell mentioned this pull request Apr 21, 2020
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.

Use locally defined exception classes instead of raising generic exception types.
4 participants