nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: gphotosuploader/gphotos-uploader-cli
Pull request #212 (2020-08-04 06:16:09)

Stop on album creation error
Instead of uploading the photo without an album.

/kind bug



Patch:
diff --git a/upload/enqueue.go b/upload/enqueue.go
index 8c57462..a707ad1 100644
--- a/upload/enqueue.go
+++ b/upload/enqueue.go
@@ -2,6 +2,7 @@ package upload
 
 import (
 	"context"
+	"fmt"
 	"os"
 
 	"github.com/gphotosuploader/gphotos-uploader-cli/log"
@@ -19,8 +20,14 @@ type EnqueuedJob struct {
 }
 
 func (job *EnqueuedJob) Process() error {
+	// Get or create the album
+	albumId, err := job.albumID()
+	if err != nil {
+		return err
+	}
+
 	// Upload the file and add it to PhotosService.
-	_, err := job.PhotosService.AddMediaItem(job.Context, job.Path, job.albumID())
+	_, err = job.PhotosService.AddMediaItem(job.Context, job.Path, albumId)
 	if err != nil {
 		return err
 	}
@@ -45,16 +52,15 @@ func (job *EnqueuedJob) ID() string {
 }
 
 // albumID returns the album ID of the created (or existent) album in PhotosService.
-func (job *EnqueuedJob) albumID() string {
+func (job *EnqueuedJob) albumID() (string, error) {
 	// Return if empty to avoid a PhotosService call.
 	if job.AlbumName == "" {
-		return ""
+		return "", nil
 	}
 
 	album, err := job.PhotosService.GetOrCreateAlbumByName(job.AlbumName)
 	if err != nil {
-		job.Logger.Errorf("Album creation failed: name=%s, error=%s", job.AlbumName, err)
-		return ""
+		return "", fmt.Errorf("Album creation failed: name=%s, error=%s", job.AlbumName, err)
 	}
-	return album.Id
+	return album.Id, nil
 }


Test patch:
diff --git a/upload/enqueue_test.go b/upload/enqueue_test.go
index b59dbb3..a338265 100644
--- a/upload/enqueue_test.go
+++ b/upload/enqueue_test.go
@@ -27,13 +27,14 @@ func (m *MockedPhotosService) AddMediaItem(ctx context.Context, path string, alb
 
 func TestAlbumId(t *testing.T) {
 	var testData = []struct {
-		name string
-		in   string
-		want string
+		name         string
+		in           string
+		want         string
+		err_expected bool
 	}{
-		{name: "WithEmptyPath", in: "", want: ""},
-		{name: "WithSuccessfulCall", in: "bar", want: "testAlbumID"},
-		{name: "WithFailedCall", in: "makeMyTestFail", want: ""},
+		{name: "WithEmptyPath", in: "", want: "", err_expected: false},
+		{name: "WithSuccessfulCall", in: "bar", want: "testAlbumID", err_expected: false},
+		{name: "WithFailedCall", in: "makeMyTestFail", want: "", err_expected: true},
 	}
 
 	job := EnqueuedJob{
@@ -44,10 +45,15 @@ func TestAlbumId(t *testing.T) {
 	for _, tt := range testData {
 		t.Run(tt.name, func(t *testing.T) {
 			job.AlbumName = tt.in
-			got := job.albumID()
+			got, err := job.albumID()
 			if got != tt.want {
 				t.Errorf("albumID test failed: expected '%s', got '%s'", tt.want, got)
 			}
+			if tt.err_expected && err == nil {
+				t.Errorf("albumID test failed: expected error")
+			} else if !tt.err_expected && err != nil {
+				t.Errorf("albumID test failed: didn't expect error: '%s'", err)
+			}
 		})
 
 	}