-
Notifications
You must be signed in to change notification settings - Fork 0
docs: document Event::EncDecryptFailed (whatsapp-rust#1261) #504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8b234bd
docs: document Event::EncDecryptFailed (whatsapp-rust#1261)
claude 186d042
docs: address review feedback on PR #504
claude f9a782c
docs(client): fix the same lease-ordering race in acquire_decrypted_p…
claude a1ea9c9
docs(events): fix at-most-once correlation key for EncDecryptFailed
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,8 @@ As of PR #1195, `ErrorChainExt` also answers `http_status()` — the HTTP status | |
|
|
||
| As of PR #1257, `IqError::ServerError` also carries `response: RejectionStanza` — the `type="error"` stanza itself, handed over whole the same way a `type="result"` response already was, alongside the four fields this crate parses off it (`code`, `text`, `error_type`, `backoff`). See [`RejectionStanza`](#rejectionstanza) below. | ||
|
|
||
| As of PR #1261, `wacore::bot_message::decrypt_bot_message` (and its private decryption helper) return `Result<T, BotMessageError>` instead of `anyhow::Result<T>`. Unlike the entries above, this is **a breaking change to `wacore`'s public API**, not an additive one — a caller matching on the previous `anyhow::Error` needs to switch to the typed enum. See [`BotMessageError`](#botmessageerror) below. | ||
|
|
||
| ## Error hierarchy | ||
|
|
||
| ``` | ||
|
|
@@ -57,6 +59,13 @@ IqError (IQ request failures — embedded by most domain errors) | |
| ├── DuplicateRequestId(String) | ||
| ├── EncodeError | ||
| └── ParseError | ||
|
|
||
| BotMessageError (wacore::bot_message::decrypt_bot_message — wacore crate, not whatsapp_rust) | ||
| ├── InvalidSecretLength | ||
| ├── InvalidIvLength | ||
| ├── PayloadTooShort | ||
| ├── KeyDerivation | ||
| └── AuthenticationFailed | ||
| ``` | ||
|
|
||
| Domain errors that embed `IqError` or `ClientError` via `#[from]` propagate those failures automatically via `?`. Some errors (e.g. `AppStateError`, `SignalError`) use internal `anyhow::Error` wrapping instead and do not have `Iq` or `Client` variants. | ||
|
|
@@ -218,6 +227,7 @@ Rendering changed alongside the `source()` fix: a wrapping variant's `Display` s | |
| | `ConnectError` | `Client::connect`, `Client::wait_for_socket`, `Client::wait_for_connected` | `whatsapp_rust` | | ||
| | `SignalMaintenanceError` | `Client::rotate_signed_pre_key`, `Client::flush_pending_signal_state` | `whatsapp_rust` | | ||
| | `MessageEditError` | `EncryptedEdit::original_sender_jid`, `SecretEncrypted::original_sender_jid`, `SecretEncrypted::original_sender_for_dispatch` | `whatsapp_rust` | | ||
| | `BotMessageError` | `wacore::bot_message::decrypt_bot_message` | `wacore` | | ||
|
|
||
| ## Type definitions | ||
|
|
||
|
|
@@ -569,6 +579,44 @@ pub enum MessageEditError { | |
|
|
||
| Both variants mean the peer sent a target message key that cannot be attributed — retrying the same envelope yields the same result. `MessageEditError` is re-exported from the crate root as `whatsapp_rust::MessageEditError`. | ||
|
|
||
| ### BotMessageError | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Format the type name as code. Use 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
|
|
||
| Returned by `wacore::bot_message::decrypt_bot_message` and its private decryption helper. Added in PR #1261, replacing bare `anyhow::Result`. | ||
|
|
||
| <Note> | ||
| Unlike every other error type on this page, `BotMessageError` lives in the `wacore` crate, not `whatsapp_rust` — and its introduction is **a breaking change to `wacore`'s public API**: `decrypt_bot_message`'s return type changed from `anyhow::Result<T>` to `Result<T, BotMessageError>`, so a caller matching on the previous `anyhow::Error` needs to switch to this typed enum. | ||
| </Note> | ||
|
|
||
| ```rust | ||
| #[non_exhaustive] | ||
| pub enum BotMessageError { | ||
| InvalidSecretLength, | ||
| InvalidIvLength, | ||
| PayloadTooShort, | ||
| KeyDerivation, | ||
| AuthenticationFailed, | ||
| } | ||
| ``` | ||
|
|
||
| **Variants:** | ||
| - `InvalidSecretLength` — the bot message secret is not the expected size. | ||
| - `InvalidIvLength` — the IV carried by the payload is not the expected size. | ||
| - `PayloadTooShort` — the payload is too short to contain what it claims to. | ||
| - `KeyDerivation` — deriving the decryption key from the secret failed. | ||
| - `AuthenticationFailed` — the ciphertext did not verify (AES-GCM tag mismatch). | ||
|
|
||
| `BotMessageError::stage(&self) -> BotMessageFailure` classifies which stage of decryption a failure belongs to, without matching every variant by name: | ||
|
|
||
| ```rust | ||
| pub enum BotMessageFailure { | ||
| Envelope, | ||
| Secret, | ||
| Authentication, | ||
| } | ||
| ``` | ||
|
|
||
| Use `stage()` when you only care whether the envelope, the secret, or the authentication step failed — for metrics or a coarse retry policy — rather than the specific `BotMessageError` variant. | ||
|
|
||
| ### ClientError (base type) | ||
|
|
||
| ```rust | ||
|
|
@@ -846,3 +894,28 @@ let err: IqError = wacore_err.into(); | |
| // After — pass the response the classification failure was read from | ||
| let err = IqError::from_response(wacore_err, &response); | ||
| ``` | ||
|
|
||
| ### From PR #1261: `decrypt_bot_message` returns a typed error | ||
|
|
||
| If you were matching on `anyhow::Error` from `wacore::bot_message::decrypt_bot_message`, switch to [`BotMessageError`](#botmessageerror): | ||
|
|
||
| ```rust | ||
| // Before | ||
| match decrypt_bot_message(message_secret, enc_iv, enc_payload, &ctx) { | ||
| Ok(plaintext) => { /* ... */ } | ||
| Err(e) => eprintln!("bot message decrypt failed: {e}"), | ||
| } | ||
|
|
||
| // After — match specific variants, or classify by stage | ||
| use wacore::bot_message::{BotMessageError, BotMessageFailure}; | ||
|
|
||
| match decrypt_bot_message(message_secret, enc_iv, enc_payload, &ctx) { | ||
| Ok(plaintext) => { /* ... */ } | ||
| Err(e @ BotMessageError::AuthenticationFailed) => eprintln!("tampered or wrong secret: {e}"), | ||
| Err(e) => match e.stage() { | ||
| BotMessageFailure::Envelope => eprintln!("malformed envelope: {e}"), | ||
| BotMessageFailure::Secret => eprintln!("bad secret: {e}"), | ||
| BotMessageFailure::Authentication => eprintln!("authentication failed: {e}"), | ||
| }, | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| ``` | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
Use direct reader guidance and split the contract details.
Lines 2074-2081 use third-person consumers. They also combine activation, event scope, numbering, and cost behavior in long sentences. Use “you” and separate each guarantee into its own sentence.
Proposed wording
As per coding guidelines, use active voice and second-person wording, and keep one idea per sentence.
🤖 Prompt for AI Agents
Source: Coding guidelines