Lonami / grammers

(tele)gramme.rs - use Telegram's API from Rust
https://t.me/gramme_rs
Apache License 2.0
535 stars 103 forks source link

panics when receiving an update #258

Closed taimast closed 3 weeks ago

taimast commented 3 weeks ago
pub fn listen_client_updates(
        client: Client,
        sender: Sender<DispatcherUpdate>,
    ) -> JoinHandle<()> {
        tokio::spawn(async move {
            log::info!("Start listening client updates");
            loop {
                let upd = client.next_update().await;
                log::info!("Received update from client {:?}", &upd);
                match upd {
                    Ok(Update::NewMessage(msg)) => {
                        log::info!("Received new message UPDATE {:?}", &msg.text());
                        let send = sender.send(DispatcherUpdate::NewMessage(msg)).await;
                        if send.is_err() {
                            log::error!("Failed to send update to dispatcher");
                            break;
                        }
                    }
                    Err(err) => {
                        log::error!("Failed to get update from client: {:?}", err);
                        break;
                    }
                    _ => {
                        log::info!("Received unknown update\n{:#?}", upd);
                    }
                }
            }
        })
    }
2024-08-21T01:22:36.966Z INFO  [grammers_session::message_box] received an update referencing an unknown peer, treating as gap
thread 'tokio-runtime-worker' panicked at C:\Users\taima\.cargo\git\checkouts\grammers-4b9fa1a66debb2aa\eb2f119\lib\grammers-session\src\message_box\mod.rs:742:47:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'tokio-runtime-worker' panicked at C:\Users\taima\.cargo\git\checkouts\grammers-4b9fa1a66debb2aa\eb2f119\lib\grammers-client\src\client\updates.rs:265:41:       
called `Result::unwrap()` on an `Err` value: PoisonError { .. }
Lonami commented 3 weeks ago

In other places of the code we also optionally get the secret entry. So I guess this fix is fair.