googleapis / googleapis/google-cloud-go
spanner: add better support for updating a row that may not exist
- Dominant language
- Go
- Stars
- 4.5k
- Forks
- 1.6k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 109
Description
## Is your feature request related to a problem? Please describe.
This is a feature request similar to #10031.
In methods like `ReadRow` and `ReadRowUsingIndex`, we can now handle cases where a row does not exist using `spanner.ErrRecordNotFound`.
It would be helpful if similar support were available for mutations such as `Update`, `UpdateMap`, and `UpdateStruct`.
These mutations return a NotFound error when the target row does not exist, but the same NotFound error is also returned when the database or table does not exist, making it difficult to distinguish between the two cases.
## Describe the solution you'd like
For `Apply` or `BufferWrite` that execute `Update`, `UpdateMap`, or `UpdateStruct` mutations, return a more distinguishable and catchable error such as `spanner.ErrRecordNotFound` when the target row does not exist.
## Describe alternatives you've considered
Use `ErrDetails` from `apierror` to handle the error when the row is not found:
https://pkg.go.dev/github.com/googleapis/gax-go/v2/apierror#ErrDetails
The Spanner API would need to return a documented and handleable `ErrorInfo` in such cases.
## Additional context
NA
Contributor guide
Assessment
This issue has not been assessed yet.