Skip to content

Commit

Permalink
Fix error in With function signature and add test case for With function
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mizutani committed Jan 13, 2024
1 parent 4907101 commit 3feee99
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (x *Error) Unwrap() error {
}

// With adds key and value related to the error event
func (x *Error) With(key string, value any) *Error {
func (x *Error) With(key, value any) *Error {
x.values[key] = value
return x
}
Expand Down
6 changes: 6 additions & 0 deletions test/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,9 @@ func TestLoggingNestedError(t *testing.T) {
assert.Contains(t, out.String(), `"number":"five"`)
assert.Contains(t, out.String(), `"color":"orange"`)
}

func TestWithAnyKey(t *testing.T) {
type myKey struct{}
err := goerr.New("e1").With(myKey{}, "orange")
assert.Equal(t, "orange", err.Values()[myKey{}])
}

0 comments on commit 3feee99

Please sign in to comment.