Skip to content

Commit

Permalink
return nil when wrap nil error (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
taxio authored Jan 8, 2024
1 parent caa564a commit 78d2015
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions error.go
Original file line number Diff line number Diff line change
@@ -69,6 +69,10 @@ func Unwrap(err error) error {
}

func Wrap(err error, annotators ...Annotator) error {
if err == nil {
return nil
}

e := &Error{
message: "",
err: err,
7 changes: 7 additions & 0 deletions errors_test.go
Original file line number Diff line number Diff line change
@@ -87,6 +87,13 @@ func TestWrap(t *testing.T) {
}
})
}

t.Run("wrap nil", func(t *testing.T) {
err := errors.Wrap(nil)
if err != nil {
t.Errorf("expected nil, got %s", err.Error())
}
})
}

func TestWithStack(t *testing.T) {

0 comments on commit 78d2015

Please sign in to comment.