teloxide icon indicating copy to clipboard operation
teloxide copied to clipboard

Parse Error: Data did not match any variant of untagged enum TelegramResponse for `getStickerSet`

Open Avimitin opened this issue 2 years ago • 7 comments

When using get_sticker_set method I've got RequestError::InvalidJson error with the following description:

 err = InvalidJson {
    source: Error("data did not match any variant of untagged enum TelegramResponse", line: 0, column: 0),
    raw: "{\"ok\":true,\"result\":{\"name\":\"***\",\"title\":\"***\",\"sticker_type\":\"regular\",\"contains_masks\":false,\"stickers\":[{\"width\":512,\"height\":288,\"emoji\":\"\\ud83d\\udcad\",\"set_name\":\"***\",\"is_animated\":false,\"is_video\":false,\"type\":\"regular\",\"thumbnail\":{\"file_id\":\"***\",\"file_unique_id\":\"***\",\"file_size\":7896,\"width\":320,\"height\":180},\"thumb\":{\"file_id\":\"***\",\"file_unique_id\":\"***\",\"file_size\":7896,\"width\":320,\"height\":180},\"file_id\":\"***\",\"file_unique_id\":\"***\",\"file_size\":14572}]}}",
}

Steps to reproduce

let sticker_set = bot.get_sticker_set("my_sticker_name").await.unwrap();

Meta

  • teloxide version: 0.12.2

Additional context

Avimitin avatar Apr 03 '24 09:04 Avimitin

I think this is a result of a missing #[serde(default)] on StickerKind::Regular::premium_animation: https://github.com/teloxide/teloxide/blob/fb2865b7cc48e19f5431ea65514ed25e2176d98a/crates/teloxide-core/src/types/sticker.rs#L64-L67

WaffleLapkin avatar Apr 03 '24 14:04 WaffleLapkin

But Option<T> should have Default trait impl with None as default value? https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=ceaea5c407a5d5eb826aa6b5c3efcf92

Avimitin avatar Apr 04 '24 08:04 Avimitin

@Avimitin this is mostly irrelevant. We use serde via macros, which do not have access to the type information and can't change Deserialize implementation depending on if type implements Default or not. That's why #[serde(default)] annotation exists -- to tell the macros to use the Default impl.

WaffleLapkin avatar Apr 04 '24 09:04 WaffleLapkin

Bot API 7.2 introduces "Mixed-Format Sticker Packs". This change removes is_animated and is_video from StickerSet.

I think it's enough to just remove this line: https://github.com/teloxide/teloxide/blob/384811ab4ba8771e4ff30730bf1b7e14156031b1/crates/teloxide-core/src/types/sticker_set.rs#L22-L26

avoonix avatar Apr 14 '24 21:04 avoonix

Is this being worked on? If not I could try to do it

avoonix avatar Apr 17 '24 04:04 avoonix

I don't think anyone is working on this, you may go ahead

WaffleLapkin avatar Apr 17 '24 11:04 WaffleLapkin

It seems that the maintainers did not pay attention to this issue 🤔

AH-dark avatar May 09 '24 11:05 AH-dark

Fixed by #1040 (right, @syrtcevvi?).

WaffleLapkin avatar Jul 08 '24 15:07 WaffleLapkin

all right

syrtcevvi avatar Jul 08 '24 15:07 syrtcevvi