Skip to content

Commit b52f921

Browse files
committed
GODRIVER-3853 Update erroring logic.
1 parent 48ba30a commit b52f921

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

internal/integration/unified/session_operation_execution.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func executeWithTransaction(ctx context.Context, op *operation, loopDone <-chan
109109
for idx, oper := range operations {
110110
res, execErr := oper.execute(ctx, loopDone)
111111
if execErr != nil {
112+
// Capture the error but continue executing the remaining operations in the callback.
112113
err = fmt.Errorf("error executing operation %q at index %d: %v", oper.Name, idx, execErr)
113114
return nil, nil
114115
}

mongo/errors.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,10 +834,11 @@ type TimeoutError struct {
834834

835835
// Error implements the error interface.
836836
func (e TimeoutError) Error() string {
837+
const timeoutMsg = "operation timed out"
837838
if e.Wrapped == nil {
838-
return "operation timed out"
839+
return timeoutMsg
839840
}
840-
return e.Wrapped.Error()
841+
return fmt.Sprintf("%s: %v", timeoutMsg, e.Wrapped.Error())
841842
}
842843

843844
// Unwrap returns the underlying error.

mongo/session.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,14 @@ func (s *Session) WithTransaction(
217217
return res, nil
218218
}
219219

220-
select {
221-
case <-timeout.C:
222-
return res, TimeoutError{Wrapped: err}
223-
default:
224-
}
225-
226220
var cerr CommandError
227221
if errors.As(err, &cerr) {
228222
if cerr.HasErrorLabel(driver.UnknownTransactionCommitResult) && !cerr.IsMaxTimeMSExpiredError() {
223+
select {
224+
case <-timeout.C:
225+
return res, TimeoutError{Wrapped: err}
226+
default:
227+
}
229228
continue
230229
}
231230
if cerr.HasErrorLabel(driver.TransientTransactionError) {

0 commit comments

Comments
 (0)