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

Use pointer receiver for type-defined errors #161

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type ErrTaken struct {
Nodes []int
}

func (err ErrTaken) Error() string {
func (err *ErrTaken) Error() string {
return fmt.Sprintf("lock already taken, locked nodes: %v", err.Nodes)
}

Expand All @@ -31,7 +31,7 @@ type ErrNodeTaken struct {
Node int
}

func (err ErrNodeTaken) Error() string {
func (err *ErrNodeTaken) Error() string {
return fmt.Sprintf("node #%d: lock already taken", err.Node)
}

Expand All @@ -41,10 +41,10 @@ type RedisError struct {
Err error
}

func (e RedisError) Error() string {
func (e *RedisError) Error() string {
return fmt.Sprintf("node #%d: %s", e.Node, e.Err)
}

func (e RedisError) Unwrap() error {
func (e *RedisError) Unwrap() error {
return e.Err
}
4 changes: 2 additions & 2 deletions error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestRedisErrorIs(t *testing.T) {
for k, v := range cases {

t.Run(k, func(t *testing.T) {
err := RedisError{
err := &RedisError{
Node: 0,
Err: v,
}
Expand All @@ -39,7 +39,7 @@ func TestRedisErrorAs(t *testing.T) {
for k, v := range cases {

t.Run(k, func(t *testing.T) {
err := RedisError{
err := &RedisError{
Node: 0,
Err: v,
}
Expand Down
7 changes: 5 additions & 2 deletions mutex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,11 @@ func TestMutexQuorum(t *testing.T) {
assertAcquired(ctx, t, v.pools, mutex)
} else {
err := mutex.Lock()
if errors.Is(err, &ErrNodeTaken{}) {
t.Fatalf("Expected err == %q, got %q", ErrNodeTaken{}, err)
target := &ErrNodeTaken{
Node: 0,
}
if errors.Is(err, target) {
t.Fatalf("Expected err == %q, got %q", target, err)
}
}
}
Expand Down