Skip to content

Commit

Permalink
Merge pull request #123 from rafiss/max-retry-error
Browse files Browse the repository at this point in the history
Make max retry error show correct message
  • Loading branch information
rafiss committed Jan 19, 2022
2 parents 561007c + f431ea8 commit 7a4e302
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crdb/error.go
Expand Up @@ -71,6 +71,9 @@ func newMaxRetriesExceededError(err error, maxRetries int) *MaxRetriesExceededEr
}
}

// Error implements the error interface.
func (e *MaxRetriesExceededError) Error() string { return e.msg }

// TxnRestartError represents an error when restarting a transaction. `cause` is
// the error from restarting the txn and `retryCause` is the original error which
// triggered the restart.
Expand Down
29 changes: 29 additions & 0 deletions crdb/error_test.go
@@ -0,0 +1,29 @@
// Copyright 2022 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package crdb

import (
"errors"
"fmt"
"strings"
"testing"
)

func TestMaxRetriesExceededError(t *testing.T) {
origError := fmt.Errorf("root error")
err := newMaxRetriesExceededError(origError, 10)
if !strings.HasPrefix(err.Error(), "retrying txn failed after 10 attempts.") {
t.Fatalf("expected txn retry error message")
}
if !errors.Is(err, origError) {
t.Fatal("expected to find root error cause")
}
}

0 comments on commit 7a4e302

Please sign in to comment.