fix: log connection state when unable to attach#653
Conversation
WalkthroughThe attach flow in the Ably realtime channel now caches the connection state in a local variable instead of repeatedly accessing it. The error message reported on validation failure was updated to reflect the actual connection state value rather than the channel state. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
ably/realtime/realtime_channel.py (1)
240-245: Consider applying the same fix to thedetach()method.Similar to the issue fixed in
attach(), this error message shows the channel state when the condition is actually checking the connection state. For consistency and clarity, consider updating this to show the connection state instead.Apply this diff to align with the fix in
attach():+ connection_state = self.__realtime.connection.state - if self.__realtime.connection.state in [ConnectionState.CLOSING, ConnectionState.FAILED]: + if connection_state in [ConnectionState.CLOSING, ConnectionState.FAILED]: raise AblyException( - message=f"Unable to detach; channel state = {self.state}", + message=f"Unable to detach channel; connection state = {connection_state}", code=90001, status_code=400 )
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
ably/realtime/realtime_channel.py(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
ably/realtime/realtime_channel.py (4)
ably/realtime/realtime.py (1)
connection(132-134)ably/realtime/connection.py (2)
state(109-111)state(120-121)ably/realtime/connectionmanager.py (1)
state(765-766)ably/types/connectionstate.py (1)
ConnectionState(8-16)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: check (3.14)
- GitHub Check: check (3.12)
- GitHub Check: check (3.13)
- GitHub Check: check (3.8)
- GitHub Check: check (3.9)
- GitHub Check: check (3.11)
- GitHub Check: check (3.10)
🔇 Additional comments (1)
ably/realtime/realtime_channel.py (1)
186-193: LGTM! Error message now correctly reflects the connection state.The changes properly address the issue where the error message was showing the channel state instead of the connection state that was actually preventing the attach. Caching the connection state also improves consistency and avoids multiple property accesses.
80f347d to
8085a4f
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
ably/realtime/channel.py (1)
187-192:⚠️ Potential issue | 🟡 MinorSame bug exists here: error message reports channel state but checks connection state.
The
detachmethod has the same issue that was fixed inattach. The condition checksconnection.statebut the error message incorrectly reports the channel state.🐛 Proposed fix to match the attach() fix
+ connection_state = self.__realtime.connection.state # RTL5g, RTL5b - raise exception if state invalid - if self.__realtime.connection.state in [ConnectionState.CLOSING, ConnectionState.FAILED]: + if connection_state in [ConnectionState.CLOSING, ConnectionState.FAILED]: raise AblyException( - message=f"Unable to detach; channel state = {self.state}", + message=f"Unable to detach channel; connection state = {connection_state}", code=90001, status_code=400 )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ably/realtime/channel.py` around lines 187 - 192, The error raised in detach() checks self.__realtime.connection.state but the AblyException message reports the channel state (self.state); update the message in the detach() AblyException to reflect the connection state (e.g., include self.__realtime.connection.state) or include both states for clarity so the message matches the condition checked (refer to detach, attach, AblyException, self.__realtime.connection.state, self.state).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@ably/realtime/channel.py`:
- Around line 187-192: The error raised in detach() checks
self.__realtime.connection.state but the AblyException message reports the
channel state (self.state); update the message in the detach() AblyException to
reflect the connection state (e.g., include self.__realtime.connection.state) or
include both states for clarity so the message matches the condition checked
(refer to detach, attach, AblyException, self.__realtime.connection.state,
self.state).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d163931c-4d78-41f8-a274-117be35096a9
📒 Files selected for processing (1)
ably/realtime/channel.py
this log was unhelpfully printing the channel state when it's actually the connection state preventing the channel from attaching
Summary by CodeRabbit