Skip to content

Commit

Permalink
fix(firestore): Fix documented error code returned by `DocumentSnapsh…
Browse files Browse the repository at this point in the history
…otIterator.Next()` (#2595)

DocumentSnapshotIterator.Next() can return either a Canceled or DeadlineExceeded error depending on how the context was canceled.

Co-authored-by: Hidehito Yabuuchi <ordovicia@users.noreply.github.com>
Co-authored-by: Chris Cotter <cjcotter@google.com>
  • Loading branch information
3 people committed Jun 23, 2022
1 parent 44e37cc commit b454472
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions firestore/listen_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ func listenErrors(ctx context.Context, w io.Writer, projectID, collection string
it := client.Collection(collection).Snapshots(ctx)
for {
snap, err := it.Next()
// DeadlineExceeded will be returned when ctx is cancelled.
if status.Code(err) == codes.DeadlineExceeded {
// Canceled will be returned when ctx is cancelled and DeadlineExceeded will
// be returned when ctx reaches its deadline.
if e := status.Code(err); e == codes.Canceled || e == codes.DeadlineExceeded {
return nil
}
if err != nil {
Expand Down

0 comments on commit b454472

Please sign in to comment.