-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix(spanner): wrap errors in inline begin transaction to avoid masking #8273
base: main
Are you sure you want to change the base?
fix(spanner): wrap errors in inline begin transaction to avoid masking #8273
Conversation
…mask original errors
@harshachinta Thanks for picking this up, please add the test case to mock the invalid SQL statement and check if the invalid SQL error message is contained in the final error. |
@harshachinta I'd be happy to take over this changeset and help push it through if thats ok with you. We run into this fairly frequently so this change would be greatly beneficial. |
@ajorgensen Feel free to work on top of this. I guess the changes in this PR is working as expected except there was some test failures. I don't exactly recall the pending stuff in this PR. Will try taking a look at this next week. |
@harshachinta I found one more spot that looks to be missing a bit of extra information that is available. EDIT: Never mind I figured it out... required a bit of url hacking on the pull-request screen to make a PR against your fork but I think this should work: harshachinta#5
or if its easier here is the patch: diff --git a/spanner/transaction.go b/spanner/transaction.go
index dab7ceb76a..6fedf82165 100644
--- a/spanner/transaction.go
+++ b/spanner/transaction.go
@@ -1216,14 +1216,22 @@ func (t *ReadWriteTransaction) batchUpdateWithOptions(ctx context.Context, stmts
}
counts = append(counts, count)
}
+
+ if resp.Status != nil && resp.Status.Code != 0 {
+ err = spannerErrorf(codes.Code(uint32(resp.Status.Code)), resp.Status.Message)
+ if hasInlineBeginTransaction && !haveTransactionID {
+ t.setTransactionID(nil)
+ return counts, toSpannerErrorDuringInlineBegin(err)
+ }
+
+ return counts, err
+ }
+
if hasInlineBeginTransaction && !haveTransactionID {
// retry with explicit BeginTransaction
t.setTransactionID(nil)
return counts, errInlineBeginTransactionFailed()
}
- if resp.Status != nil && resp.Status.Code != 0 {
- return counts, spannerErrorf(codes.Code(uint32(resp.Status.Code)), resp.Status.Message)
- }
return counts, nil
} here is a fix for the failing client_test as well: diff --git a/spanner/session.go b/spanner/session.go
index 547ed464bc..27c309ad68 100644
--- a/spanner/session.go
+++ b/spanner/session.go
@@ -1656,7 +1656,7 @@ func isFailedInlineBeginTransaction(err error) bool {
if err == nil {
return false
}
- return strings.Contains(err.Error(), errInlineBeginTransactionFailed().Error())
+ return strings.Contains(err.Error(), inlineBeginTransactionFailedMsg)
}
// isClientClosing returns true if the given error is a |
@rahul2393 do we still want to accecpt this PR? |
This P.R would have saved me a LOT of time. Could we get this merged please? Its a great improvement |
@rahul2393 please see my comment above |
When inline begin transaction was added, the error messages were getting masked with
This PR fixes this by wrapping the error to unmask original errors.