Skip to content

Commit

Permalink
update as per discussions
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul2393 committed Jun 21, 2024
1 parent 4db25ab commit b550e3b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions spanner/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package spanner

import (
"context"
"errors"
"fmt"

"github.com/googleapis/gax-go/v2/apierror"
Expand All @@ -26,6 +27,10 @@ import (
"google.golang.org/grpc/status"
)

var (
ErrRecordNotFound = errors.New("record not found")

Check failure on line 31 in spanner/errors.go

View workflow job for this annotation

GitHub Actions / vet

exported var ErrRecordNotFound should have comment or be unexported
)

// Error is the structured error returned by Cloud Spanner client.
//
// Deprecated: Unwrap any error that is returned by the Spanner client as an APIError
Expand Down
8 changes: 4 additions & 4 deletions spanner/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1731,8 +1731,8 @@ func TestIntegration_Reads(t *testing.T) {
if ErrCode(err) != codes.NotFound {
t.Fatalf("got %v, want NotFound", err)
}
if !errors.Is(err, iterator.Done) {
t.Fatalf("got %v, want iterator.Done", err)
if !errors.Is(err, ErrRecordNotFound) {
t.Fatalf("got %v, want spanner.ErrRecordNotFound", err)
}
verifyDirectPathRemoteAddress(t)

Expand All @@ -1754,8 +1754,8 @@ func TestIntegration_Reads(t *testing.T) {
if ErrCode(err) != codes.NotFound {
t.Fatalf("got %v, want NotFound", err)
}
if !errors.Is(err, iterator.Done) {
t.Fatalf("got %v, want iterator.Done", err)
if !errors.Is(err, ErrRecordNotFound) {
t.Fatalf("got %v, want spanner.ErrRecordNotFound", err)
}
verifyDirectPathRemoteAddress(t)
rangeReads(ctx, t, client)
Expand Down
8 changes: 4 additions & 4 deletions spanner/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,14 @@ func (t *txReadOnly) ReadWithOptions(ctx context.Context, table string, keys Key
// key.
func errRowNotFound(table string, key Key) error {
err := spannerErrorf(codes.NotFound, "row not found(Table: %v, PrimaryKey: %v)", table, key)
err.(*Error).err = iterator.Done
err.(*Error).err = ErrRecordNotFound
return err
}

// errRowNotFoundByIndex returns error for not being able to read the row by index.
func errRowNotFoundByIndex(table string, key Key, index string) error {
err := spannerErrorf(codes.NotFound, "row not found(Table: %v, IndexKey: %v, Index: %v)", table, key, index)
err.(*Error).err = iterator.Done
err.(*Error).err = ErrRecordNotFound
return err
}

Expand All @@ -350,7 +350,7 @@ func errInlineBeginTransactionFailed() error {

// ReadRow reads a single row from the database.
//
// If no row is present with the given key, then ReadRow returns an error where
// If no row is present with the given key, then ReadRow returns an error(spanner.ErrRecordNotFound) where
// spanner.ErrCode(err) is codes.NotFound.
func (t *txReadOnly) ReadRow(ctx context.Context, table string, key Key, columns []string) (*Row, error) {
return t.ReadRowWithOptions(ctx, table, key, columns, nil)
Expand All @@ -377,7 +377,7 @@ func (t *txReadOnly) ReadRowWithOptions(ctx context.Context, table string, key K
// ReadRowUsingIndex reads a single row from the database using an index.
//
// If no row is present with the given index, then ReadRowUsingIndex returns an
// error where spanner.ErrCode(err) is codes.NotFound.
// error(spanner.ErrRecordNotFound) where spanner.ErrCode(err) is codes.NotFound.
//
// If more than one row received with the given index, then ReadRowUsingIndex
// returns an error where spanner.ErrCode(err) is codes.FailedPrecondition.
Expand Down

0 comments on commit b550e3b

Please sign in to comment.