[GH-ISSUE #363] Progress time received from API can be negative #113

Closed
opened 2026-02-27 20:23:11 +03:00 by kerem · 5 comments
Owner

Originally created by @bamode on GitHub (Oct 15, 2022).
Original GitHub issue: https://github.com/ramsayleung/rspotify/issues/363

Describe the bug
This issue effects specifically the structs CurrentlyPlayingContext and CurrentPlaybackContext when deserializing the Spotify API response that corresponds to the progress field of these structs. It appears to be parsing it as a u32 to turn into a std::time::Duration and this part of the API response is occasionally a negative number. This results in upstream bugs in the spotifyd and spotify-tui projects.

Expected behavior
The API deserialization should be able to replace an unexpected negative time value with some default.

Originally created by @bamode on GitHub (Oct 15, 2022). Original GitHub issue: https://github.com/ramsayleung/rspotify/issues/363 **Describe the bug** This issue effects specifically the structs `CurrentlyPlayingContext` and `CurrentPlaybackContext` when deserializing the Spotify API response that corresponds to the `progress` field of these structs. It appears to be parsing it as a `u32` to turn into a `std::time::Duration` and this part of the API response is occasionally a negative number. This results in upstream bugs in the spotifyd and spotify-tui projects. **Expected behavior** The API deserialization should be able to replace an unexpected negative time value with some default.
kerem 2026-02-27 20:23:11 +03:00
Author
Owner

@ramsayleung commented on GitHub (Oct 15, 2022):

Thanks for your report, The Spotify's documentation doesn't point out the progress could be a negative number.

If progress could be a negative number, then parsing it as an u32 to turn into a std::time::Duration is inappropriate. std::time::Duration doesn't support negative value.

I would like to replace std::time::Duration to chrono::Duration, which supports negative value. It would be a break change.

<!-- gh-comment-id:1279664029 --> @ramsayleung commented on GitHub (Oct 15, 2022): Thanks for your report, The Spotify's documentation doesn't point out the `progress` could be a negative number. If `progress` could be a negative number, then parsing it as an `u32` to turn into a `std::time::Duration` is inappropriate. `std::time::Duration` doesn't support negative value. I would like to replace `std::time::Duration` to `chrono::Duration`, which supports negative value. It would be a break change.
Author
Owner

@ramsayleung commented on GitHub (Oct 19, 2022):

If we consider replacing std::time::Duration to chrono::Duration, we need to replace all fields using std::time::Duration to chrono::Duration. Otherwise, it will become inconsistent that some fields are using std::time::Duration to represent time, other fields are using chrono::Duration to represent time.

<!-- gh-comment-id:1284011715 --> @ramsayleung commented on GitHub (Oct 19, 2022): If we consider replacing `std::time::Duration` to `chrono::Duration`, we need to replace all [fields](https://github.com/ramsayleung/rspotify/search?l=Rust&q=Duration) using `std::time::Duration` to `chrono::Duration`. Otherwise, it will become inconsistent that some fields are using `std::time::Duration` to represent time, other fields are using `chrono::Duration` to represent time.
Author
Owner

@marioortizmanero commented on GitHub (Dec 26, 2022):

Do we know in which cases we receive a negative value? Another option is to have a custom serializer that sets these cases to zero, though I do prefer to represent the API as closely as possible with chrono::Duration.

<!-- gh-comment-id:1365281483 --> @marioortizmanero commented on GitHub (Dec 26, 2022): Do we know in which cases we receive a negative value? Another option is to have a custom serializer that sets these cases to zero, though I do prefer to represent the API as closely as possible with `chrono::Duration`.
Author
Owner

@ramsayleung commented on GitHub (Dec 27, 2022):

As @bamode points out, the progress field in CurrentlyPlayingContext could be negative. I think it doesn't make sense if we set these cases to zero.

<!-- gh-comment-id:1365724784 --> @ramsayleung commented on GitHub (Dec 27, 2022): As @bamode points out, the `progress` field in `CurrentlyPlayingContext ` could be negative. I think it doesn't make sense if we set these cases to zero.
Author
Owner

@github-actions[bot] commented on GitHub (Jun 24, 2023):

Message to comment on stale issues. If none provided, will not mark issues stale

<!-- gh-comment-id:1605241318 --> @github-actions[bot] commented on GitHub (Jun 24, 2023): Message to comment on stale issues. If none provided, will not mark issues stale
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/rspotify#113
No description provided.