happyleavesaoc / python-snapcast

Python API for controlling Snapcast, a multi-room synchronous audio solution.
MIT License
70 stars 28 forks source link

Exceptions thrown when debug logging is enabled #61

Closed mill1000 closed 8 months ago

mill1000 commented 9 months ago

When logging is configured for DEBUG the following exceptions are thrown upon connecting to my Snapcast server.

DEBUG:snapcast.control.server:connected to snapserver on wyseguy:1705
DEBUG:snapcast.control.server:stream found: Snapstream (UPnP)
DEBUG:snapcast.control.server:stream found: Snapstream (Airplay)
DEBUG:snapcast.control.server:stream found: Snapstream (Spotify)
DEBUG:snapcast.control.server:stream found: Snapstream (All Streams)
--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib/python3.11/logging/__init__.py", line 1110, in emit
    msg = self.format(record)
          ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/logging/__init__.py", line 953, in format
    return fmt.format(record)
           ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/logging/__init__.py", line 687, in format
    record.message = record.getMessage()
                     ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/logging/__init__.py", line 377, in getMessage
    msg = msg % self.args
          ~~~~^~~~~~~~~~~
  File "/net/wyseguy/mnt/ssd/projects/snapcast-monitor/.venv/lib/python3.11/site-packages/snapcast/control/group.py", line 193, in __repr__
    return f'Snapgroup ({self.friendly_name}, {self.identifier})'
                         ^^^^^^^^^^^^^^^^^^
  File "/net/wyseguy/mnt/ssd/projects/snapcast-monitor/.venv/lib/python3.11/site-packages/snapcast/control/group.py", line 109, in friendly_name
    sorted([self._server.client(c).friendly_name for c in self.clients]))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/net/wyseguy/mnt/ssd/projects/snapcast-monitor/.venv/lib/python3.11/site-packages/snapcast/control/group.py", line 109, in <listcomp>
    sorted([self._server.client(c).friendly_name for c in self.clients]))
            ^^^^^^^^^^^^^^^^^^^^^^
  File "/net/wyseguy/mnt/ssd/projects/snapcast-monitor/.venv/lib/python3.11/site-packages/snapcast/control/server.py", line 251, in client
    return self._clients[client_identifier]
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
KeyError: 'b8:27:eb:e3:17:de'
Call stack:
  File "/net/wyseguy/mnt/ssd/projects/snapcast-monitor/./error.py", line 18, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
  File "/usr/lib/python3.11/asyncio/base_events.py", line 640, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.11/asyncio/base_events.py", line 607, in run_forever
    self._run_once()
  File "/usr/lib/python3.11/asyncio/base_events.py", line 1922, in _run_once
    handle._run()
  File "/usr/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/net/wyseguy/mnt/ssd/projects/snapcast-monitor/./error.py", line 14, in main
    await snapcast.control.create_server(loop, "wyseguy")
  File "/net/wyseguy/mnt/ssd/projects/snapcast-monitor/.venv/lib/python3.11/site-packages/snapcast/control/__init__.py", line 9, in create_server
    await server.start()
  File "/net/wyseguy/mnt/ssd/projects/snapcast-monitor/.venv/lib/python3.11/site-packages/snapcast/control/server.py", line 115, in start
    self.synchronize(status)
  File "/net/wyseguy/mnt/ssd/projects/snapcast-monitor/.venv/lib/python3.11/site-packages/snapcast/control/server.py", line 287, in synchronize
    _LOGGER.debug('group found: %s', new_groups[group.get('id')])
Unable to print the message and arguments - possible formatting error.
Use the traceback above to help find the error.
DEBUG:snapcast.control.server:client found: Snapclient 0.27.0 (StereoBerry, b8:27:eb:e3:17:de)
--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib/python3.11/logging/__init__.py", line 1110, in emit
    msg = self.format(record)
          ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/logging/__init__.py", line 953, in format
    return fmt.format(record)
           ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/logging/__init__.py", line 687, in format
    record.message = record.getMessage()
                     ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/logging/__init__.py", line 377, in getMessage
    msg = msg % self.args
          ~~~~^~~~~~~~~~~
  File "/net/wyseguy/mnt/ssd/projects/snapcast-monitor/.venv/lib/python3.11/site-packages/snapcast/control/group.py", line 193, in __repr__
    return f'Snapgroup ({self.friendly_name}, {self.identifier})'
                         ^^^^^^^^^^^^^^^^^^
  File "/net/wyseguy/mnt/ssd/projects/snapcast-monitor/.venv/lib/python3.11/site-packages/snapcast/control/group.py", line 109, in friendly_name
    sorted([self._server.client(c).friendly_name for c in self.clients]))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/net/wyseguy/mnt/ssd/projects/snapcast-monitor/.venv/lib/python3.11/site-packages/snapcast/control/group.py", line 109, in <listcomp>
    sorted([self._server.client(c).friendly_name for c in self.clients]))
            ^^^^^^^^^^^^^^^^^^^^^^
  File "/net/wyseguy/mnt/ssd/projects/snapcast-monitor/.venv/lib/python3.11/site-packages/snapcast/control/server.py", line 251, in client
    return self._clients[client_identifier]
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
KeyError: 'b8:27:eb:43:7e:9f'
Call stack:
  File "/net/wyseguy/mnt/ssd/projects/snapcast-monitor/./error.py", line 18, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
  File "/usr/lib/python3.11/asyncio/base_events.py", line 640, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.11/asyncio/base_events.py", line 607, in run_forever
    self._run_once()
  File "/usr/lib/python3.11/asyncio/base_events.py", line 1922, in _run_once
    handle._run()
  File "/usr/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/net/wyseguy/mnt/ssd/projects/snapcast-monitor/./error.py", line 14, in main
    await snapcast.control.create_server(loop, "wyseguy")
  File "/net/wyseguy/mnt/ssd/projects/snapcast-monitor/.venv/lib/python3.11/site-packages/snapcast/control/__init__.py", line 9, in create_server
    await server.start()
  File "/net/wyseguy/mnt/ssd/projects/snapcast-monitor/.venv/lib/python3.11/site-packages/snapcast/control/server.py", line 115, in start
    self.synchronize(status)
  File "/net/wyseguy/mnt/ssd/projects/snapcast-monitor/.venv/lib/python3.11/site-packages/snapcast/control/server.py", line 287, in synchronize
    _LOGGER.debug('group found: %s', new_groups[group.get('id')])
Unable to print the message and arguments - possible formatting error.
Use the traceback above to help find the error.
DEBUG:snapcast.control.server:client found: Snapclient 0.27.0 (NoteBerry, b8:27:eb:43:7e:9f)
DEBUG:snapcast.control.server:Server connected

Script to recreate

#!/usr/bin/env python3

import asyncio
import logging

import snapcast.control

async def main():
    logging.basicConfig(level=logging.DEBUG)

    # Connect to the Snapcast server
    loop = asyncio.get_running_loop()
    await snapcast.control.create_server(loop, "wyseguy")

try:
    asyncio.run(main())
except KeyboardInterrupt:
    pass