Revise error handling to be more consistent for library users - #180
Conversation
…e DeviceException for invalid tokens / checksum errors
* DeviceExceptions are catched in the base group (ExceptionHandlerGroup) * Token & ip validation is moved to click_common module
| sys.exit(1) | ||
|
|
||
| import miio # noqa: E402 | ||
| from miio.click_common import (ExceptionHandlerGroup, validate_ip, |
There was a problem hiding this comment.
module level import not at top of file
| sys.exit(1) | ||
|
|
||
| import miio # noqa: E402 | ||
| from miio.click_common import (ExceptionHandlerGroup, validate_ip, |
There was a problem hiding this comment.
module level import not at top of file
| sys.exit(1) | ||
|
|
||
| import miio # noqa: E402 | ||
| from miio.click_common import (ExceptionHandlerGroup, validate_ip, |
There was a problem hiding this comment.
module level import not at top of file
| sys.exit(1) | ||
|
|
||
| import miio # noqa: E402 | ||
| from miio.click_common import (ExceptionHandlerGroup, validate_ip, |
There was a problem hiding this comment.
module level import not at top of file
| import click | ||
| import ipaddress | ||
| import miio | ||
| import logging |
There was a problem hiding this comment.
module level import not at top of file
|
|
||
| import click | ||
| import ipaddress | ||
| import miio |
There was a problem hiding this comment.
module level import not at top of file
| sys.exit(1) | ||
|
|
||
| import click | ||
| import ipaddress |
There was a problem hiding this comment.
module level import not at top of file
| sys.version_info) | ||
| sys.exit(1) | ||
|
|
||
| import click |
There was a problem hiding this comment.
module level import not at top of file
| print("To use this script you need python 3.4 or newer, got %s" % | ||
| sys.version_info) | ||
| sys.exit(1) | ||
| import click |
There was a problem hiding this comment.
module level import not at top of file
There was a problem hiding this comment.
The printout has to be before trying to import miio as otherwise it'll bail out with syntax errors.
Users of the library can catch
miio.DeviceExceptionfor catching both communication errors as well as errors reported by the devices (which are of typemiio.DeviceErrorextending fromDeviceException).