MartijnBraam / python-isc-dhcp-leases

Small python module for reading /var/lib/dhcp/dhcpd.leases from isc-dhcp-server
MIT License
122 stars 46 forks source link

Added an exception when no binding available. #17

Closed marksabbath closed 7 years ago

marksabbath commented 7 years ago

Raise a properly exception when no binding property is available in dhcp.leases file.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.8%) to 99.162% when pulling 4e47ef7924faf102209b7f5344652ce78c659d4a on marksabbath:hotfix/error-when-no-binding-available into cd2a500205fc5afe42405140612090036be2da29 on MartijnBraam:master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.8%) to 99.162% when pulling fd68b0a22499644c85409d6673456677fa58b53a on marksabbath:hotfix/error-when-no-binding-available into cd2a500205fc5afe42405140612090036be2da29 on MartijnBraam:master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.8%) to 99.162% when pulling bf9c5bc7143bb5407c8cace970ffb1dee877d31e on marksabbath:hotfix/error-when-no-binding-available into cd2a500205fc5afe42405140612090036be2da29 on MartijnBraam:master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.8%) to 99.162% when pulling bf9c5bc7143bb5407c8cace970ffb1dee877d31e on marksabbath:hotfix/error-when-no-binding-available into cd2a500205fc5afe42405140612090036be2da29 on MartijnBraam:master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.8%) to 99.162% when pulling bf9c5bc7143bb5407c8cace970ffb1dee877d31e on marksabbath:hotfix/error-when-no-binding-available into cd2a500205fc5afe42405140612090036be2da29 on MartijnBraam:master.

MartijnBraam commented 7 years ago

Since this is a library I don't think that the code should call print(), that is something the calling program should handle. I think the best way to handle this is to raise a custom exception that the input file is invalid so the calling program can decide what to do with the file.

Calling exit in a library is a whole other level of things not to do. We shouldn't kill the main program on a parsing error.

Maybe instead of wrapping a simple key lookup in a try..except block we can use an if block to check if the property exists before using it.

marksabbath commented 7 years ago

Totally agree @MartijnBraam I'm gonna close this one and build a new branch from scratch following your suggestion.