Skip to content

Commit f431ea8

Browse files
committed
Make max retry error show correct message
1 parent 561007c commit f431ea8

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

crdb/error.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ func newMaxRetriesExceededError(err error, maxRetries int) *MaxRetriesExceededEr
7171
}
7272
}
7373

74+
// Error implements the error interface.
75+
func (e *MaxRetriesExceededError) Error() string { return e.msg }
76+
7477
// TxnRestartError represents an error when restarting a transaction. `cause` is
7578
// the error from restarting the txn and `retryCause` is the original error which
7679
// triggered the restart.

crdb/error_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2022 The Cockroach Authors.
2+
//
3+
// Use of this software is governed by the Business Source License
4+
// included in the file licenses/BSL.txt.
5+
//
6+
// As of the Change Date specified in that file, in accordance with
7+
// the Business Source License, use of this software will be governed
8+
// by the Apache License, Version 2.0, included in the file
9+
// licenses/APL.txt.
10+
11+
package crdb
12+
13+
import (
14+
"errors"
15+
"fmt"
16+
"strings"
17+
"testing"
18+
)
19+
20+
func TestMaxRetriesExceededError(t *testing.T) {
21+
origError := fmt.Errorf("root error")
22+
err := newMaxRetriesExceededError(origError, 10)
23+
if !strings.HasPrefix(err.Error(), "retrying txn failed after 10 attempts.") {
24+
t.Fatalf("expected txn retry error message")
25+
}
26+
if !errors.Is(err, origError) {
27+
t.Fatal("expected to find root error cause")
28+
}
29+
}

0 commit comments

Comments
 (0)