@@ -326,12 +326,16 @@ func (t *txReadOnly) ReadWithOptions(ctx context.Context, table string, keys Key
326
326
// errRowNotFound returns error for not being able to read the row identified by
327
327
// key.
328
328
func errRowNotFound (table string , key Key ) error {
329
- return spannerErrorf (codes .NotFound , "row not found(Table: %v, PrimaryKey: %v)" , table , key )
329
+ err := spannerErrorf (codes .NotFound , "row not found(Table: %v, PrimaryKey: %v)" , table , key )
330
+ err .(* Error ).err = ErrRowNotFound
331
+ return err
330
332
}
331
333
332
334
// errRowNotFoundByIndex returns error for not being able to read the row by index.
333
335
func errRowNotFoundByIndex (table string , key Key , index string ) error {
334
- return spannerErrorf (codes .NotFound , "row not found(Table: %v, IndexKey: %v, Index: %v)" , table , key , index )
336
+ err := spannerErrorf (codes .NotFound , "row not found(Table: %v, IndexKey: %v, Index: %v)" , table , key , index )
337
+ err .(* Error ).err = ErrRowNotFound
338
+ return err
335
339
}
336
340
337
341
// errMultipleRowsFound returns error for receiving more than one row when reading a single row using an index.
@@ -346,8 +350,14 @@ func errInlineBeginTransactionFailed() error {
346
350
347
351
// ReadRow reads a single row from the database.
348
352
//
349
- // If no row is present with the given key, then ReadRow returns an error where
353
+ // If no row is present with the given key, then ReadRow returns an error(spanner.ErrRowNotFound) where
350
354
// spanner.ErrCode(err) is codes.NotFound.
355
+ //
356
+ // To check if the error is spanner.ErrRowNotFound:
357
+ //
358
+ // if errors.Is(err, spanner.ErrRowNotFound) {
359
+ // ...
360
+ // }
351
361
func (t * txReadOnly ) ReadRow (ctx context.Context , table string , key Key , columns []string ) (* Row , error ) {
352
362
return t .ReadRowWithOptions (ctx , table , key , columns , nil )
353
363
}
@@ -356,6 +366,12 @@ func (t *txReadOnly) ReadRow(ctx context.Context, table string, key Key, columns
356
366
//
357
367
// If no row is present with the given key, then ReadRowWithOptions returns an error where
358
368
// spanner.ErrCode(err) is codes.NotFound.
369
+ //
370
+ // To check if the error is spanner.ErrRowNotFound:
371
+ //
372
+ // if errors.Is(err, spanner.ErrRowNotFound) {
373
+ // ...
374
+ // }
359
375
func (t * txReadOnly ) ReadRowWithOptions (ctx context.Context , table string , key Key , columns []string , opts * ReadOptions ) (* Row , error ) {
360
376
iter := t .ReadWithOptions (ctx , table , key , columns , opts )
361
377
defer iter .Stop ()
@@ -373,7 +389,13 @@ func (t *txReadOnly) ReadRowWithOptions(ctx context.Context, table string, key K
373
389
// ReadRowUsingIndex reads a single row from the database using an index.
374
390
//
375
391
// If no row is present with the given index, then ReadRowUsingIndex returns an
376
- // error where spanner.ErrCode(err) is codes.NotFound.
392
+ // error(spanner.ErrRowNotFound) where spanner.ErrCode(err) is codes.NotFound.
393
+ //
394
+ // To check if the error is spanner.ErrRowNotFound:
395
+ //
396
+ // if errors.Is(err, spanner.ErrRowNotFound) {
397
+ // ...
398
+ // }
377
399
//
378
400
// If more than one row received with the given index, then ReadRowUsingIndex
379
401
// returns an error where spanner.ErrCode(err) is codes.FailedPrecondition.
0 commit comments