Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(spanner): demonstrate enhanced row not found handling options #10031 #10358

Closed
wants to merge 1 commit into from

Conversation

husam-e
Copy link

@husam-e husam-e commented Jun 11, 2024

This change is just an example (that may not build successfully yet) demonstrating 2 options for enhancing row not found handling, which is currently not explicit when using ReadRow / ReadRowUsingIndex, as discussed in #10031:

  1. Setting the returned APIError's Details.ErrorInfo.Reason to a well-defined value that can be checked by users to reliably determine if an error is specifically due to a row not being found (as opposed to column/table not found which returns the same error code).
  2. Introducing an additional API that returns nil when the row is not found (called ReadRowOptional). An equivalent API would be added for ReadRowUsingIndex (ReadRowOptionalUsingIndex).

Copy link

google-cla bot commented Jun 11, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@product-auto-label product-auto-label bot added the api: spanner Issues related to the Spanner API. label Jun 11, 2024
@@ -326,7 +328,8 @@ func (t *txReadOnly) ReadWithOptions(ctx context.Context, table string, keys Key
// errRowNotFound returns error for not being able to read the row identified by
// key.
func errRowNotFound(table string, key Key) error {
return spannerErrorf(codes.NotFound, "row not found(Table: %v, PrimaryKey: %v)", table, key)
details := []protoadapt.MessageV1{&errdetails.ErrorInfo{Reason: RowNotFoundReason}}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

option 1: specify an explicit and exported Reason value in details.ErrorInfo.Reason, and do the same for ReadRowUsingIndex

// This is a convenience function to simplify use cases that want to treat
// a missing row as nil in a reliable manner, without matching against the
// error message.
func (t *txReadOnly) ReadRowOptional(ctx context.Context, table string, key Key, columns []string) (*Row, error) {
Copy link
Author

@husam-e husam-e Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

option 2: additional API for treating row not found as nil and not an error (and doing the same for ReadRowUsingIndex

@husam-e
Copy link
Author

husam-e commented Jun 21, 2024

Addressed in #10405, thanks @rahul2393 !

@husam-e husam-e closed this Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the Spanner API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant