Skip to content

Raise a proper error when the bridge can't be reached - #83

Merged
michaelarnauts merged 1 commit into
masterfrom
unreachable-bridge
Aug 2, 2026
Merged

Raise a proper error when the bridge can't be reached#83
michaelarnauts merged 1 commit into
masterfrom
unreachable-bridge

Conversation

@michaelarnauts

Copy link
Copy Markdown
Owner

Opening the connection only translated asyncio.TimeoutError:

try:
    self._reader, self._writer = await asyncio.wait_for(asyncio.open_connection(self.host, self.PORT), TIMEOUT)
except asyncio.TimeoutError as exc:
    raise AioComfoConnectTimeout("Timeout while connecting to bridge") from exc

Everything else that asyncio.open_connection() can raise came out as a bare OSError: a refused connection, a bridge that is gone from the network, a hostname that no longer resolves. That is not something a caller can reasonably catch, and it is what the reporter of home-assistant-comfoconnect#100 ran into:

OSError: [Errno 113] Connect call failed (192.168.178.142, 56747)

It also ended up in the catch-all handler of the reconnect loop, which logs the full traceback, every five seconds for as long as the bridge stays away.

OSError is now translated to a new AioComfoConnectNotReachable, and the reconnect loop retries it the same way it retries a timeout, with a one line warning instead of a traceback.

Some notes:

  • The TimeoutError handler has to stay above the OSError one, since TimeoutError is a subclass of OSError. There is a comment saying so.
  • ComfoConnectNotReachable already exists but means something else, the gateway telling us it cannot route a request to a node, so this needs its own exception. It is in the Aio family with the other connection level errors.
  • The new tests cover an unreachable host, a refused connection and a name that does not resolve.

For the Home Assistant integration this needs a small follow up: it catches AioComfoConnectTimeout to trigger the rediscovery that handles a bridge that changed address, and AioComfoConnectNotReachable should trigger the same path.

🤖 Generated with Claude Code

Only asyncio.TimeoutError was translated when opening the connection, so
everything else that asyncio.open_connection raises, a refused
connection, a host that is gone from the network, a hostname that doesn't
resolve, escaped as a bare OSError. Callers can't reasonably catch that,
and in the reconnect loop it ended up in the catch-all handler, which
logged a full traceback every five seconds for as long as the bridge
stayed away.

Translate it to AioComfoConnectNotReachable and retry it like a timeout.
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.

1 participant