fix: guard public API methods against calls while disconnected#55
Merged
toddr merged 2 commits intocpan-authors:mainfrom Mar 20, 2026
Merged
Conversation
Demonstrates that ChangeStatus, GetRoster, GetStatus, and Process all crash with "Can't call method on an undefined value" when called after Disconnect(). These tests will pass once the guards are added. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ChangeStatus, GetRoster, GetStatus, Process, JoinForum, AddUser, and RmUser all crash with "Can't call method on an undefined value" when called after Disconnect() sets jabber_client to undef. Add IsConnected checks matching the existing pattern in _send_individual_message: log a warning and return a safe value instead of crashing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
toddr
approved these changes
Mar 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Add IsConnected guards to all public methods that directly access jabber_client.
Why
After
Disconnect(),jabber_clientis set toundef. CallingChangeStatus,GetRoster,GetStatus,Process,JoinForum,AddUser, orRmUserin that state crashes with "Can't call method on an undefined value." This can happen when user code calls these methods from a background function or after a network failure._send_individual_messagealready had this guard — the other public methods were missing it.How
Each method now checks
IsConnectedbefore touchingjabber_client. Return values match what callers would expect:ChangeStatusreturns 0,GetRosterreturns empty list,GetStatusreturns "unavailable",Processreturns undef.Testing
t/07-test_disconnect_public_api.t(9 tests) — first commit shows failures, second adds the fix.🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 102 insertions(+)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline