-
Notifications
You must be signed in to change notification settings - Fork 0
docs: per-domain typed errors (whatsapp-rust#893) #346
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
Changes from 6 commits
bcceead
81c96d2
8eccdd6
47fec50
1c49979
a2486c9
79b0872
b6eeae3
e00724b
242fda6
fee3654
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ pub async fn archive_chat( | |
| &self, | ||
| jid: &Jid, | ||
| message_range: Option<SyncActionMessageRange>, | ||
| ) -> Result<()> | ||
| ) -> Result<(), AppStateError> | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
@@ -46,7 +46,7 @@ pub async fn unarchive_chat( | |
| &self, | ||
| jid: &Jid, | ||
| message_range: Option<SyncActionMessageRange>, | ||
| ) -> Result<()> | ||
| ) -> Result<(), AppStateError> | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
@@ -65,7 +65,7 @@ client.chat_actions().unarchive_chat(&jid, None).await?; | |
| Pin a chat to keep it at the top of the chat list. | ||
|
|
||
| ```rust | ||
| pub async fn pin_chat(&self, jid: &Jid) -> Result<()> | ||
| pub async fn pin_chat(&self, jid: &Jid) -> Result<(), AppStateError> | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
@@ -86,7 +86,7 @@ WhatsApp limits the number of pinned chats. Attempting to pin too many chats may | |
| Unpin a chat. | ||
|
|
||
| ```rust | ||
| pub async fn unpin_chat(&self, jid: &Jid) -> Result<()> | ||
| pub async fn unpin_chat(&self, jid: &Jid) -> Result<(), AppStateError> | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
@@ -104,7 +104,7 @@ client.chat_actions().unpin_chat(&jid).await?; | |
| Mute a chat indefinitely. | ||
|
|
||
| ```rust | ||
| pub async fn mute_chat(&self, jid: &Jid) -> Result<()> | ||
| pub async fn mute_chat(&self, jid: &Jid) -> Result<(), AppStateError> | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
@@ -125,7 +125,7 @@ pub async fn mute_chat_until( | |
| &self, | ||
| jid: &Jid, | ||
| mute_end_timestamp_ms: i64 | ||
| ) -> Result<()> | ||
| ) -> Result<(), AppStateError> | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
@@ -156,7 +156,7 @@ client.chat_actions() | |
| Unmute a chat. | ||
|
|
||
| ```rust | ||
| pub async fn unmute_chat(&self, jid: &Jid) -> Result<()> | ||
| pub async fn unmute_chat(&self, jid: &Jid) -> Result<(), AppStateError> | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
@@ -180,7 +180,7 @@ pub async fn star_message( | |
| participant_jid: Option<&Jid>, | ||
| message_id: &str, | ||
| from_me: bool | ||
| ) -> Result<()> | ||
| ) -> Result<(), AppStateError> | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
@@ -223,7 +223,7 @@ pub async fn unstar_message( | |
| participant_jid: Option<&Jid>, | ||
| message_id: &str, | ||
| from_me: bool | ||
| ) -> Result<()> | ||
| ) -> Result<(), AppStateError> | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
@@ -248,7 +248,7 @@ pub async fn mark_chat_as_read( | |
| jid: &Jid, | ||
| read: bool, | ||
| message_range: Option<SyncActionMessageRange>, | ||
| ) -> Result<()> | ||
| ) -> Result<(), AppStateError> | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
@@ -283,7 +283,7 @@ pub async fn delete_chat( | |
| jid: &Jid, | ||
| delete_media: bool, | ||
| message_range: Option<SyncActionMessageRange>, | ||
| ) -> Result<()> | ||
| ) -> Result<(), AppStateError> | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
@@ -319,7 +319,7 @@ pub async fn clear_chat( | |
| delete_starred: bool, | ||
| delete_media: bool, | ||
| message_range: Option<SyncActionMessageRange>, | ||
| ) -> Result<()> | ||
| ) -> Result<(), AppStateError> | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
@@ -356,7 +356,7 @@ pub async fn save_contact( | |
| full_name: Option<String>, | ||
| first_name: Option<String>, | ||
| save_on_primary_addressbook: bool, | ||
| ) -> Result<()> | ||
| ) -> Result<(), AppStateError> | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
@@ -385,7 +385,7 @@ pub async fn set_user_status_mute( | |
| &self, | ||
| jid: &Jid, | ||
| muted: bool, | ||
| ) -> Result<()> | ||
| ) -> Result<(), AppStateError> | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
@@ -417,7 +417,7 @@ pub async fn delete_message_for_me( | |
| from_me: bool, | ||
| delete_media: bool, | ||
| message_timestamp: Option<i64>, | ||
| ) -> Result<()> | ||
| ) -> Result<(), AppStateError> | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
@@ -489,7 +489,7 @@ pub async fn send_app_state_action( | |
| schema: &Schema, | ||
| index_args: &[&str], | ||
| value: &wa::SyncActionValue, | ||
| ) -> Result<()> | ||
| ) -> Result<(), AppStateError> | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
@@ -592,17 +592,30 @@ use wacore::types::events::Event; | |
|
|
||
| ## Error handling | ||
|
|
||
| All methods return `Result<(), anyhow::Error>`. Common errors: | ||
| All methods return `Result<(), AppStateError>`: | ||
|
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.
This section now says all chat actions return Useful? React with 👍 / 👎. |
||
|
|
||
| - No app state sync key available (sync not complete) | ||
| - Invalid timestamp for `mute_chat_until` | ||
| - Missing `participant_jid` for group star/delete operations | ||
| - Network errors | ||
| ```rust | ||
| #[derive(Debug, thiserror::Error)] | ||
| #[non_exhaustive] | ||
| pub enum AppStateError { | ||
| #[error("invalid app-state request: {0}")] | ||
| InvalidRequest(String), | ||
| #[error(transparent)] | ||
| Internal(#[from] anyhow::Error), | ||
| } | ||
| ``` | ||
|
|
||
| You'll encounter these most often: | ||
| - `InvalidRequest` — you passed an invalid timestamp to `mute_chat_until` or omitted `participant_jid` for a group operation | ||
| - `Internal` — no app state sync key is available yet (sync not complete), or a network error occurred | ||
|
|
||
| ```rust | ||
| use whatsapp_rust::AppStateError; | ||
|
|
||
| match client.chat_actions().mute_chat_until(&jid, 0).await { | ||
| Ok(_) => println!("Muted"), | ||
| Err(e) => eprintln!("Failed: {}", e), // Timestamp validation error | ||
| Err(AppStateError::InvalidRequest(msg)) => eprintln!("Validation error: {}", msg), | ||
| Err(e) => eprintln!("Failed: {}", e), | ||
| } | ||
| ``` | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.