Lonami / grammers

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

Thread panicking when calling `message.download_media()` #216

Closed IMXEren closed 10 months ago

IMXEren commented 10 months ago

Issue

thread 'main' panicked at /home/imxeren/.cargo/git/checkouts/grammers-b702bdb11c87df45/e4116c7/lib/grammers-client/src/client/files.rs:37:87:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

On update handler, the method panics if the media isn't downloadable for example, in case of polls etc. Looking on the description,

Download the message media in this message if applicable.

Returns true if there was media to download, or false otherwise.

I guess that it shouldn't panic and return an Err and ultimately returns false on message.download_media().

Possible Solution

On navigating, I notice that the issue is how the method handles the download by invoking downloadable.to_input_location() which returns None. So, a check inside the fn download_media and returns Err if downloadable.to_input_location() is None, can possibly fix this.

Lonami commented 10 months ago

I don't think I'll get to this soon, but you seem to have figured out the problem, so feel free to send a PR.

IMXEren commented 10 months ago

Sorry, I committed some changes but couldn't test it well (busy with the exams). Now, created a PR.