MaxOhn / rosu-v2

A rust wrapper for the osu!api v2
MIT License
24 stars 9 forks source link

Deserialisation failing from osu lazer api? #22

Closed Dcs1729 closed 5 months ago

Dcs1729 commented 5 months ago

Hi, I apologise in advance if I've made a mistake and this is something on my end.

The wrapper seems to be failing to deserialise responses from the lazer api as of the last day or so. I haven't changed my code at all so I suspect a change may have been made to the lazer resposne format?

I'm currently getting an error upon running this function

pub async fn get_recent_score(osu: &Osu, user_id: impl Into<UserId>, index: usize, include_fails: bool) -> Option<Score> {
    let res = osu
        .user_scores(user_id)
        .recent()
        .mode(GameMode::Osu)
        .include_fails(include_fails)
        .offset(index)
        .limit(1)
        .await;

    match res {
        Err(OsuError::NotFound) => None,
        Err(e) => panic!("failed to get recent score: {}", e),
        Ok(scores) => {
            scores.first().cloned()
        }
    }
}

Which gives me a Parsing Varianet of the OsuError e.g. running this on my own user ID gives:

failed to get recent score: failed to deserialize response: [{"ranked":true,"preserve":true,"processed":true,"maximum_statistics":{"great":547,"legacy_combo_increase":249},"mods":[{"acronym":"EZ"},{"acronym":"CL"}],"statistics":{"ok":76,"meh":8,"miss":51,"great":412},"beatmap_id":3103318,"best_id":null,"id":2732442911,"rank":"B","type":"solo_score","user_id":19357648,"accuracy":0.80195,"build_id":null,"ended_at":"2024-04-26T13:02:02Z","has_replay":false,"is_perfect_combo":false,"legacy_perfect":false,"legacy_score_id":4618270719,"legacy_total_score":575745,"max_combo":136,"passed":true,"pp":0.020622,"ruleset_id":0,"started_at":null,"total_score":127544,"replay":false,"current_user_attributes":{"pin":null},"beatmap":{"beatmapset_id":1512813,"difficulty_rating":6.24,"id":3103318,"mode":"osu","status":"ranked","total_length":134,"user_id":9088487,"version":"Deca's Expert","aclast_updated":"2021-08-15T19:31:21Z","mode_int":0,"passcount":27723,"playcount":172315,"ranked":1,"url":"https:\/\/osu.ppy.sh\/beatmaps\/3103318","checksum":"5546117d00d133dc48ed304e29558859"},"beatmapset":{"artist":"Paramore","artist_unicode":"Paramore","covers":{"cover":"https:\/\/assets.ppy.sh\/beatmaps\/1512813\/covers\/cover.jpg?1629055899","cover@2x":"https:\/\/assets.ppy.sh\/beatmaps\/1512813\/covers\/cover@2x.jpg?1629055899","card":"https:\/\/assets.ppy.sh\/beatmaps\/1512813\/covers\/card.jpg?1629055899","card@2x":"https:\/\/assets.ppy.sh\/beatmaps\/1512813\/covers\/card@2x.jpg?1629055899","list":"https:\/\/assets.ppy.sh\/beatmaps\/1512813\/covers\/list.jpg?1629055899","list@2x":"https:\/\/assets.ppy.sh\/beatmaps\/1512813\/covers\/list@2x.jpg?1629055899","slimcover":"https:\/\/assets.ppy.sh\/beatmaps\/1512813\/covers\/slimcover.jpg?1629055899","slimcover@2x":"https:\/\/assets.ppy.sh\/beatmaps\/1512813\/covers\/slimcover@2x.jpg?1629055899"},"creator":"attendant","favourite_count":556,"hype":null,"id":1512813,"nsfw":false,"offset":0,"play_count":629594,"preview_url":"\/\/b.ppy.sh\/preview\/1512813.mp3","source":"","spotlight":false,"status":"ranked","title":"Anklebiters","title_unicode":"Anklebiters","track_id":null,"user_id":12416885,"video":false},"user":{"avatar_url":"https:\/\/a.ppy.sh\/19357648?1710019187.jpeg","country_code":"GB","default_group":"default","id":19357648,"is_active":true,"is_bot":false,"is_deleted":false,"is_online":true,"is_supporter":true,"last_visit":"2024-04-26T17:37:56+00:00","pm_friends_only":false,"profile_colour":null,"username":"Dcs"}}]

I'm using this line in my Cargo.toml: rosu-v2-lazer = {package="rosu-v2", git = "https://github.com/MaxOhn/rosu-v2", branch = "lazer", features = ["replay"] }

Apologies again if I've made a mistake, otherwise I'd be happy to help if you need any other information to help solve the issue.

MaxOhn commented 5 months ago

Indeed they added a new field to scores just recently which isn't a problem in of itself but the deserialization is currently configured to be extra sensitive to make sure no change goes unnoticed.

I''ve already pushed a fix so I believe a simple cargo update -p rosu-v2 should do the trick for you.

Dcs1729 commented 5 months ago

Ah, thank you! I appreciate the info.