Skip to content
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

Make max retry error show correct message #123

Merged
merged 1 commit into from Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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")
}
}