Return immediately when StreamSharedState cannot be parsed.

PiperOrigin-RevId: 256026123
Change-Id: I50895d5e938caf989ebff2061b6d09ad52576d92
diff --git a/src/main/java/com/google/android/libraries/feed/feedstore/internal/PersistentFeedStore.java b/src/main/java/com/google/android/libraries/feed/feedstore/internal/PersistentFeedStore.java
index b167147..fbab4dd 100644
--- a/src/main/java/com/google/android/libraries/feed/feedstore/internal/PersistentFeedStore.java
+++ b/src/main/java/com/google/android/libraries/feed/feedstore/internal/PersistentFeedStore.java
@@ -152,8 +152,9 @@
       try {
         sharedStates.add(StreamSharedState.parseFrom(byteArray));
       } catch (InvalidProtocolBufferException e) {
-        tracker.stop("getSharedStates", "failed");
         Logger.e(TAG, e, "Error parsing protocol buffer from bytes %s", byteArray);
+        tracker.stop("getSharedStates", "failed");
+        return Result.failure();
       }
     }
     tracker.stop("", "getSharedStates", "items", sharedStates.size());
diff --git a/src/test/java/com/google/android/libraries/feed/feedstore/internal/PersistentFeedStoreTest.java b/src/test/java/com/google/android/libraries/feed/feedstore/internal/PersistentFeedStoreTest.java
index 3658bd0..9895bc8 100644
--- a/src/test/java/com/google/android/libraries/feed/feedstore/internal/PersistentFeedStoreTest.java
+++ b/src/test/java/com/google/android/libraries/feed/feedstore/internal/PersistentFeedStoreTest.java
@@ -14,6 +14,7 @@
 
 package com.google.android.libraries.feed.feedstore.internal;
 
+import static com.google.android.libraries.feed.feedstore.internal.FeedStoreConstants.SHARED_STATE_PREFIX;
 import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doAnswer;
@@ -411,4 +412,33 @@
     assertThat(uploadableActionsResult.isSuccessful()).isTrue();
     assertThat(uploadableActionsResult.getValue()).isEmpty();
   }
+
+  @Test
+  public void getSharedStates_noContent() {
+    Result<List<StreamSharedState>> result = getStore(mainThreadRunner).getSharedStates();
+    assertThat(result.isSuccessful()).isTrue();
+    assertThat(result.getValue()).isEmpty();
+  }
+
+  @Test
+  public void getSharedStates_withContent() {
+    StreamSharedState sharedState = StreamSharedState.newBuilder().setContentId("foo").build();
+    contentStorage.commit(
+        new ContentMutation.Builder()
+            .upsert(SHARED_STATE_PREFIX + "bar", sharedState.toByteArray())
+            .build());
+
+    Result<List<StreamSharedState>> result = getStore(mainThreadRunner).getSharedStates();
+    assertThat(result.isSuccessful()).isTrue();
+    assertThat(result.getValue()).containsExactly(sharedState);
+  }
+
+  @Test
+  public void getSharedStates_cannotParse() {
+    contentStorage.commit(
+        new ContentMutation.Builder().upsert(SHARED_STATE_PREFIX + "bar", new byte[] {5}).build());
+
+    Result<List<StreamSharedState>> result = getStore(mainThreadRunner).getSharedStates();
+    assertThat(result.isSuccessful()).isFalse();
+  }
 }