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

Revise error handling to be more consistent for library users #180

Merged
merged 5 commits into from
Jan 27, 2018

Conversation

rytilahti
Copy link
Owner

@rytilahti rytilahti commented Jan 24, 2018

Users of the library can catch miio.DeviceException for catching both communication errors as well as errors reported by the devices (which are of type miio.DeviceError extending from DeviceException).

  • Wrap errors coming from the device inside DeviceError exception, raise DeviceException for invalid tokens / checksum errors
  • All client tools are modified to handle device errors

…e DeviceException for invalid tokens / checksum errors
@coveralls
Copy link

coveralls commented Jan 25, 2018

Coverage Status

Coverage increased (+2.7%) to 65.182% when pulling 0a43d0c on errors_to_exceptions into 047704a on master.

* DeviceExceptions are catched in the base group (ExceptionHandlerGroup)
* Token & ip validation is moved to click_common module
@@ -19,31 +18,14 @@
sys.exit(1)

import miio # noqa: E402
from miio.click_common import (ExceptionHandlerGroup, validate_ip,

Choose a reason for hiding this comment

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

module level import not at top of file

miio/plug_cli.py Outdated
@@ -12,27 +11,14 @@
sys.exit(1)

import miio # noqa: E402
from miio.click_common import (ExceptionHandlerGroup, validate_ip,

Choose a reason for hiding this comment

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

module level import not at top of file

@@ -10,6 +10,8 @@
sys.exit(1)

import miio # noqa: E402
from miio.click_common import (ExceptionHandlerGroup, validate_ip,

Choose a reason for hiding this comment

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

module level import not at top of file

miio/ceil_cli.py Outdated
@@ -10,6 +10,8 @@
sys.exit(1)

import miio # noqa: E402
from miio.click_common import (ExceptionHandlerGroup, validate_ip,

Choose a reason for hiding this comment

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

module level import not at top of file

@rytilahti rytilahti changed the title WIP: Wrap errors coming from the device inside DeviceError exception, rais… Wrap errors coming from the device inside DeviceError exception, rais… Jan 27, 2018
@rytilahti rytilahti changed the title Wrap errors coming from the device inside DeviceError exception, rais… Revise error handling to be more consistent for library users Jan 27, 2018
import click
import ipaddress
import miio
import logging

Choose a reason for hiding this comment

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

module level import not at top of file


import click
import ipaddress
import miio

Choose a reason for hiding this comment

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

module level import not at top of file

sys.exit(1)

import click
import ipaddress

Choose a reason for hiding this comment

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

module level import not at top of file

sys.version_info)
sys.exit(1)

import click

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

module level import not at top of file

Copy link
Owner Author

Choose a reason for hiding this comment

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

The printout has to be before trying to import miio as otherwise it'll bail out with syntax errors.

@rytilahti rytilahti merged commit ff11aed into master Jan 27, 2018
@rytilahti rytilahti deleted the errors_to_exceptions branch January 27, 2018 17:11
@rytilahti rytilahti mentioned this pull request Jan 30, 2018
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.

3 participants