Skip to content

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

Merged
rytilahti merged 5 commits into
masterfrom
errors_to_exceptions
Jan 27, 2018
Merged

Revise error handling to be more consistent for library users#180
rytilahti merged 5 commits into
masterfrom
errors_to_exceptions

Conversation

@rytilahti

@rytilahti rytilahti commented Jan 24, 2018

Copy link
Copy Markdown
Owner

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

coveralls commented Jan 25, 2018

Copy link
Copy Markdown

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
Comment thread miio/vacuum_cli.py
sys.exit(1)

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

Copy link
Copy Markdown

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

Comment thread miio/plug_cli.py
sys.exit(1)

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

Copy link
Copy Markdown

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 miio # noqa: E402
from miio.click_common import (ExceptionHandlerGroup, validate_ip,

Copy link
Copy Markdown

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

Comment thread miio/ceil_cli.py
sys.exit(1)

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

Copy link
Copy Markdown

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
Comment thread miio/click_common.py
import click
import ipaddress
import miio
import logging

Copy link
Copy Markdown

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

Comment thread miio/click_common.py

import click
import ipaddress
import miio

Copy link
Copy Markdown

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

Comment thread miio/click_common.py
sys.exit(1)

import click
import ipaddress

Copy link
Copy Markdown

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

Comment thread miio/click_common.py
sys.version_info)
sys.exit(1)

import click

Copy link
Copy Markdown

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

Comment thread miio/click_common.py
print("To use this script you need python 3.4 or newer, got %s" %
sys.version_info)
sys.exit(1)
import click

Copy link
Copy Markdown

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
Copy Markdown
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