Skip to content

Commit

Permalink
Fix Supervisor log fallback for the /follow endpoint
Browse files Browse the repository at this point in the history
When an error occurs when streaming Supervisor logs, the fallback method
receives the follow kwarg as well, which is invalid for the Docker log
handler:

 TypeError: APISupervisor.logs() got an unexpected keyword argument 'follow'

The exception is still printed to the logs but with all the extra noise
caused by this error. Removing the argument makes the stack trace more
comprehensible and the fallback actually works as desired.
  • Loading branch information
sairon committed Oct 15, 2024
1 parent 95c6389 commit e51effc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions supervisor/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ async def get_supervisor_logs(*args, **kwargs):
# No need to capture HostNotSupportedError to Sentry, the cause
# is known and reported to the user using the resolution center.
capture_exception(err)
kwargs.pop("follow", None) # Follow is not supported for Docker logs
return await api_supervisor.logs(*args, **kwargs)

self.webapp.add_routes(
Expand Down
11 changes: 11 additions & 0 deletions tests/api/test_supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ async def test_api_supervisor_fallback(
b"\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os/AppArmor\x1b[0m",
]

# check fallback also works for the follow endpoint (no mock reset needed)

with patch("supervisor.api._LOGGER.exception") as logger:
resp = await api_client.get("/supervisor/logs/follow")
logger.assert_called_once_with(
"Failed to get supervisor logs using advanced_logs API"
)

assert resp.status == 200
assert resp.content_type == "text/plain"

journald_logs.reset_mock()

# also check generic Python error
Expand Down

0 comments on commit e51effc

Please sign in to comment.