Skip to content

fix: guard public API methods against calls while disconnected#55

Merged
toddr merged 2 commits intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-disconnect-method-safety
Mar 20, 2026
Merged

fix: guard public API methods against calls while disconnected#55
toddr merged 2 commits intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-disconnect-method-safety

Conversation

@toddr-bot
Copy link
Collaborator

@toddr-bot toddr-bot commented Mar 20, 2026

What

Add IsConnected guards to all public methods that directly access jabber_client.

Why

After Disconnect(), jabber_client is set to undef. Calling ChangeStatus, GetRoster, GetStatus, Process, JoinForum, AddUser, or RmUser in 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_message already had this guard — the other public methods were missing it.

How

Each method now checks IsConnected before touching jabber_client. Return values match what callers would expect: ChangeStatus returns 0, GetRoster returns empty list, GetStatus returns "unavailable", Process returns undef.

Testing

  • New t/07-test_disconnect_public_api.t (9 tests) — first commit shows failures, second adds the fix.
  • Full suite: 327 tests pass.

🤖 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

toddr-bot and others added 2 commits March 20, 2026 21:48
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 toddr marked this pull request as ready for review March 20, 2026 21:58
@toddr toddr merged commit fb057a4 into cpan-authors:main Mar 20, 2026
20 checks passed
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.

2 participants