Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Fix: Handle null images for playlist #716

Merged
merged 4 commits into from
Jul 25, 2024

Conversation

potatoes1286
Copy link

Fixes #715, potentially #713

If a user has a playlist with no image (due to only local songs, no songs in playlist, etc), Spotify API returns a null for image and causes Spot to fail loading any playlist changes.

This turns images to an option and, if null, returns an empty image instead. It is a quick and dirty fix, but I do not know much Rust, so I've done what I could.

Thank you in advance.

@xou816

@potatoes1286
Copy link
Author

@Diegovsky @knokelmaat

@Diegovsky
Copy link
Collaborator

sorry for not seeing this earlier, I'm usually busy with my job so I don't receive notifications from gh's PRs

I'll look at it later today

@Diegovsky
Copy link
Collaborator

Also, try to target the maintenance branch as that's where current development is going

@potatoes1286
Copy link
Author

I see. My apoligies, I will try to fix that.

@potatoes1286 potatoes1286 changed the base branch from development to maintenance July 5, 2024 18:09
&self.images[..]
match &self.images {
Some(x) => &x[..],
None => &def_image[..],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we return an empty array here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Rust returns returns a value referencing data owned by the current function. I believe it has to do with garbage collection, but I do not know much rust so I just got around the issue by making a static constant outside the implementation.

@@ -186,7 +186,7 @@ trait WithImages {
pub struct Playlist {
pub id: String,
pub name: String,
pub images: Vec<Image>,
pub images: Option<Vec<Image>>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does #[serde(default)] fix the issue?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprisingly, no. I haven't investigated why but adding that to the images will still throw a null-errror.

@Diegovsky
Copy link
Collaborator

hey @potatoes1286 I added some comments but I would be happy to merge this as-is.

@potatoes1286
Copy link
Author

Any other concerns @Diegovsky or is it good to merge?

@Diegovsky
Copy link
Collaborator

@potatoes1286 please run cargo fmt

@Diegovsky
Copy link
Collaborator

I just want to make all the tests pass before merge. Looks fine by me.

I apologise for the long review process. Thank you for your contribution :)

@potatoes1286
Copy link
Author

@Diegovsky Formatted now 👍

Side note: renamed def_image -> EMPTY_IMAGE to match rust naming / more reflective naming

@Diegovsky Diegovsky merged commit cd55228 into xou816:maintenance Jul 25, 2024
2 checks passed
@Diegovsky
Copy link
Collaborator

Thank you for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spotify API error: invalid type: null
2 participants