Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions error_wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ func GetStackTrace(err error) []runtime.Frame {
func UnwrapToRoot(err error) error {
lastErr := err
for {
e := errors.Unwrap(lastErr)
if e == nil {
errs := UnwrapMulti(lastErr)
if len(errs) == 0 {
return lastErr
}
lastErr = e
lastErr = errs[0]
}
}

Expand Down
7 changes: 7 additions & 0 deletions error_wrap_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package goapperrors

import (
"errors"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -63,6 +64,12 @@ func Test_UnwrapToRoot(t *testing.T) {
e2 := Wrap(e1)
e3 := Wrap(e2)
assert.Equal(t, errTest1, UnwrapToRoot(e3))

e10 := Wrap(errTest1)
e20 := Wrap(e10)
e21 := errors.Join(e20, errors.New("test"))
e30 := Wrap(e21)
assert.Equal(t, errTest1, UnwrapToRoot(e30))
}

type err1 struct{}
Expand Down
Loading