Skip to content

docs(pair-code): document PairingCodeError, PairCodeRejection, and on_pair_code_error - #468

Merged
jlucaso1 merged 3 commits into
mainfrom
claude/nifty-bohr-2ym2fg
Jul 30, 2026
Merged

jlucaso1 merged 3 commits into
mainfrom
claude/nifty-bohr-2ym2fg

Conversation

@jlucaso1

@jlucaso1 jlucaso1 commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

Documents whatsapp-rust#1191, "feat(pair-code): report a refused pair-code request to the consumer." Client::pair_with_code previously only returned its failure as an Err; when driven by BotBuilder::with_pair_code (a detached task), that Err reached nobody, leaving a consumer waiting on a code with no way to learn none was coming. The PR adds a new event, a typed rejection status, and a bot-level handler to close that gap.

Changes

  • concepts/authentication.mdx
    • New "Pair code failure events" section documenting Event::PairingCodeError (fields, when it fires, and the two exclusions — CodeAlreadyOutstanding and Cancelled — where a code may still be on the way) and the new PairCodeRejection enum (five named variants pinned to WA Web's own accepted set, the Unknown(i32) fallback, is_throttled(), and from_server's code/text pairing rule).
    • Updated the "Pair code errors" section: PairError::RequestFailed's Display now renders exactly what it wraps instead of the fixed string "pair-code IQ request failed"; replaced the ad-hoc 400-vs-429 note with PairCodeRejection::is_throttled().
  • api/bot.mdx — new on_pair_code_error method section (mirrors the existing on_pair_code_refresh), plus a note on with_pair_code pointing at it as the only way to observe a detached-task failure.
  • api/client.mdxpair_with_code's error table and examples updated for the Display change; documented the new PairError::rejection() / backoff() / lost_the_flow_to_another_request() methods and the event dispatch that now happens alongside the returned Err.
  • concepts/events.mdx — added PairingCodeError to the Event enum listing and gave it a full entry in "Pairing Events," consistent with how PairingCode/PairingCodeRefresh are documented there.

No changelog entry — per project convention, that file is human-authored only.


Generated by Claude Code


Summary by cubic

Documents pair-code failure reporting: a PairingCodeError event, the PairCodeRejection enum, and the on_pair_code_error handler. Clarifies how Client::pair_with_code reports failures and updates RequestFailed display text, per whatsapp-rust#1191.

  • New Features

    • concepts/authentication.mdx: New “Pair code failure events” covering Event::PairingCodeError (fields, when it fires), exclusions (CodeAlreadyOutstanding, Cancelled), and PairCodeRejection variants with is_throttled(). Clarifies rejection: None only when the request never reached the server (validation/no connection/timeout) or when a named code is paired with a contradicting text; unrecognized codes return Some(Unknown(code)).
    • api/bot.mdx: Added on_pair_code_error docs and noted with_pair_code runs detached; the event is how that path reports failures. States this handler is a convenience over on_event.
    • api/client.mdx: pair_with_code now dispatches PairingCodeError on failure; documented PairError::rejection(), backoff(), and lost_the_flow_to_another_request(). Clarified RequestFailed Display renders the wrapped server error (e.g., 429 (rate-overlimit)).
    • concepts/events.mdx: Listed PairingCodeError with a concise example.
  • Bug Fixes

    • Examples: bounded throttled-retry logic (including BadRequest) in on_pair_code_error; added .. to the non-exhaustive destructuring example.
    • Corrected rejection: None docs to exclude unrecognized server codes (these map to Unknown(code)), and to include the named-code/contradicting-text case.

Written for commit 1608199. Summary will update on new commits.

…_pair_code_error

Reflects whatsapp-rust#1191: pair_with_code now dispatches
Event::PairingCodeError on failure (except CodeAlreadyOutstanding and
Cancelled) so BotBuilder::with_pair_code's detached task has a way to
report a refused request. Documents the new PairCodeRejection enum,
PairError::rejection()/backoff()/lost_the_flow_to_another_request(),
BotBuilder::on_pair_code_error, and the RequestFailed Display change.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FuiPJ7vgkeWaU7FdZJhoec
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Pair-code documentation now covers structured failure events, rejection and backoff helpers, client event dispatch behavior, and detached bot pairing error handlers.

Changes

Pairing failure events

Layer / File(s) Summary
Pairing failure event contract
concepts/events.mdx, concepts/authentication.mdx
Documents Event::PairingCodeError, its payload, rejection categories, throttling behavior, and suppressed failure cases.
Client pairing error behavior
api/client.mdx, concepts/authentication.mdx
Documents event dispatch alongside returned PairError values and adds rejection, backoff, and flow-loss helper documentation.
Detached bot pairing handling
api/bot.mdx
Documents detached with_pair_code failures and the on_pair_code_error builder handler.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

  • oxidezap/whatsapp-rust#1190 — Directly covers PairingCodeError dispatch and structured rejection/backoff reporting for detached pairing failures.

Suggested reviewers: greptile-apps

Poem

A bunny found a pairing trail,
With backoff notes instead of wail.
Events now hop when codes go wrong,
Rejection clues help folks along.
Detached tasks keep errors near—
Carrot cheers for PairingCodeError!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main documentation changes around pair-code error handling.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mintlify

mintlify Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
whatsapp-rust 🟢 Ready View Preview Jul 30, 2026, 1:08 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@api/bot.mdx`:
- Line 705: Update the documentation for on_pair_code_error to remove the claim
that it is the only way to observe with_pair_code failures, and state that
on_event also receives Event::PairingCodeError while retaining its role as the
dedicated convenience handler.
- Around line 723-730: Bound the retry loop in the throttled error handler
around client.pair_with_code so repeated PairingCodeError failures cannot
continue indefinitely. Track and enforce a maximum attempt count, or delegate
retries to the application’s retry policy, while preserving the server-provided
backoff delay for permitted retries.

In `@concepts/events.mdx`:
- Line 582: Rewrite the pairing-failure documentation in concepts/events.mdx
lines 582-582, concepts/authentication.mdx lines 525-527 and 1152-1156,
api/client.mdx line 281, and api/bot.mdx line 649 using concise, active,
second-person sentences. Separate event dispatch, returned errors, failure
classification, retry readiness, canonicalization, backoff, display behavior,
detached execution, and handler registration into distinct reader-focused
statements, preserving the documented behavior at each site.
- Around line 608-613: Update the PairingCodeError pattern in the event-handling
example to match rejection, backoff, and error while appending .. so it remains
valid for the non-exhaustive payload. Preserve the existing logging and
throttling logic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 2038260a-5a22-4882-8ac1-4e3304705e48

📥 Commits

Reviewing files that changed from the base of the PR and between 5e849af and 5d9dd02.

📒 Files selected for processing (4)
  • api/bot.mdx
  • api/client.mdx
  • concepts/authentication.mdx
  • concepts/events.mdx

Comment thread api/bot.mdx Outdated
Comment thread api/bot.mdx Outdated
Comment thread concepts/events.mdx
Comment thread concepts/events.mdx Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5d9dd02f0e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread concepts/events.mdx Outdated
Comment thread concepts/authentication.mdx Outdated
Comment thread api/bot.mdx Outdated
- Add `..` to the non-exhaustive PairingCodeError destructuring example
  (would not compile in a consumer crate) — flagged by CodeRabbit and Codex.
- Bound the throttled-retry example in on_pair_code_error to a fixed
  attempt count instead of retrying forever, including for BadRequest
  (which may be permanently invalid input, not just throttling).
- Clarify that on_pair_code_error is a convenience over on_event, not the
  only way to observe the event itself.
- Correct the rejection: None description — it also covers a server
  response whose code/text pair doesn't classify, not just "no answer".

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FuiPJ7vgkeWaU7FdZJhoec

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4b2ae1b2da

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread concepts/authentication.mdx Outdated
An unrecognized server code doesn't yield rejection: None — from_server
falls through to Some(PairCodeRejection::Unknown(code)) since Unknown's
text() is None, so the mismatch guard never fires. None only happens for
a *named* code paired with a contradicting text, or when the request
never reached the server at all. My prior fix for a related CodeRabbit
comment had this backwards.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FuiPJ7vgkeWaU7FdZJhoec
@mintlify

mintlify Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
whatsapp-rust 🟡 Building Jul 30, 2026, 1:08 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@jlucaso1
jlucaso1 merged commit fd0ab7a into main Jul 30, 2026
3 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