Skip to content

Commit

Permalink
Limit reporting of errors in Supervisor logs fallback (#5040)
Browse files Browse the repository at this point in the history
We do not need to capture HostNotSupported errors to Sentry. The only
possible code path this error might come from is where the Journal
Gateway Daemon socket is unavailable, which is already reported as an
"Unsupported system" repair.
  • Loading branch information
sairon authored Apr 25, 2024
1 parent ca8eeaa commit 2a622a9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
7 changes: 5 additions & 2 deletions supervisor/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from ..const import AddonState
from ..coresys import CoreSys, CoreSysAttributes
from ..exceptions import APIAddonNotInstalled
from ..exceptions import APIAddonNotInstalled, HostNotSupportedError
from ..utils.sentry import capture_exception
from .addons import APIAddons
from .audio import APIAudio
Expand Down Expand Up @@ -410,7 +410,10 @@ async def get_supervisor_logs(*args, **kwargs):
_LOGGER.exception(
"Failed to get supervisor logs using advanced_logs API"
)
capture_exception(err)
if not isinstance(err, HostNotSupportedError):
# No need to capture HostNotSupportedError to Sentry, the cause
# is known and reported to the user using the resolution center.
capture_exception(err)
return await api_supervisor.logs(*args, **kwargs)

self.webapp.add_routes(
Expand Down
28 changes: 27 additions & 1 deletion tests/api/test_supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
import pytest

from supervisor.coresys import CoreSys
from supervisor.exceptions import HassioError, StoreGitError, StoreNotFound
from supervisor.exceptions import (
HassioError,
HostNotSupportedError,
StoreGitError,
StoreNotFound,
)
from supervisor.store.repository import Repository

from tests.api import common_test_api_advanced_logs
Expand Down Expand Up @@ -190,6 +195,27 @@ async def test_api_supervisor_fallback(
assert resp.content_type == "text/plain"


async def test_api_supervisor_fallback_log_capture(
api_client: TestClient, journald_logs: MagicMock, docker_logs: MagicMock
):
"""Check that Sentry log capture is executed only for unexpected errors."""
journald_logs.side_effect = HostNotSupportedError(
"No systemd-journal-gatewayd Unix socket available!"
)

with patch("supervisor.api.capture_exception") as capture_exception:
await api_client.get("/supervisor/logs")
capture_exception.assert_not_called()

journald_logs.reset_mock()

journald_logs.side_effect = HassioError("Something bad happened!")

with patch("supervisor.api.capture_exception") as capture_exception:
await api_client.get("/supervisor/logs")
capture_exception.assert_called_once()


async def test_api_supervisor_reload(api_client: TestClient):
"""Test supervisor reload."""
resp = await api_client.post("/supervisor/reload")
Expand Down

0 comments on commit 2a622a9

Please sign in to comment.