gphotosuploader / google-photos-api-client-go

Google Photos API client for your Go apps
https://pkg.go.dev/github.com/gphotosuploader/google-photos-api-client-go/v3
MIT License
41 stars 20 forks source link

Panic is produced when adding media items to an album #54

Closed pacoorozco closed 3 years ago

pacoorozco commented 3 years ago

Describe the bug The bug was reported on gphotosuploader/gphotos-uploader-cli#262. In some cases (I don't know when) Google Photos response include no MediaItem. The code panics when it tries to access to a nil MediaItem.

To Reproduce When creating a media item the lines:

       mediaItemsResult := make([]MediaItem, len(result.NewMediaItemResults))
    for i, res := range result.NewMediaItemResults {
        m := res.MediaItem
        mediaItemsResult[i] = r.convertPhotosLibraryMediaItemToMediaItem(m)
    }

If result.NewMediaItemResults has some MediaItem pointing to nil, the code fails when it tries to access to it.

Expected behavior It should not panic.

Additional context The Google Photos API documentation is not saying anything about MediaItem pointing to nil on successful responses..

pacoorozco commented 3 years ago

Google Photos API could return a empty MediaItem when an error has occurred. In that case the response has a Status addressing the problem.

It's documented here

In that case, we are going to skip this returned value.

pacoorozco commented 3 years ago

Merged on master, v2.1.2