Skip to content

Response object parsing assumes presence of certain keys #320

@begincalendar

Description

@begincalendar

Describe the bug
I'm running HomeAssistant with the Matrix integration and I started seeing the following stack trace pop in my log file:

Error during setup of component matrix

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 248, in _async_setup_component
    result = await task
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/matrix/__init__.py", line 88, in setup
    bot = MatrixBot(
  File "/usr/src/homeassistant/homeassistant/components/matrix/__init__.py", line 169, in __init__
    self._client = self._login()
  File "/usr/src/homeassistant/homeassistant/components/matrix/__init__.py", line 299, in _login
    client = self._login_by_token()
  File "/usr/src/homeassistant/homeassistant/components/matrix/__init__.py", line 328, in _login_by_token
    return MatrixClient(
  File "/usr/local/lib/python3.8/site-packages/matrix_client/client.py", line 152, in __init__
    self._sync()
  File "/usr/local/lib/python3.8/site-packages/matrix_client/client.py", line 558, in _sync
    for presence_update in response['presence']['events']:
KeyError: 'presence'

Having a brief look at the code in this repo, it appears as though there are many cases where keys in the response object are assumed to always be present.
I changed the dictionary lookups with .get() calls and that seemed to fix the issue.

To Reproduce
Unfortunately I don't have a set of steps to reproduce this, it just cropped up.

Expected behavior
More robust parsing of response objects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions