Skip to content

Commit

Permalink
account for error wrapping
Browse files Browse the repository at this point in the history
Signed-off-by: Cassandra Coyle <[email protected]>
  • Loading branch information
cicoyle committed Dec 18, 2023
1 parent 31585da commit b4bce9b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ func FromError(err error) (*Error, bool) {
return nil, false
}

kitErr, ok := err.(Error)
if ok {
return &kitErr, ok
var kitErr Error
if errors.As(err, &kitErr) {
return &kitErr, true
}

return nil, false
Expand Down
6 changes: 6 additions & 0 deletions errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -967,4 +967,10 @@ func TestFromError(t *testing.T) {
if result != nil || ok {
t.Errorf("Expected result to be nil and ok to be false, got result: %#v, ok: %t", result, ok)
}

wrapped := fmt.Errorf("wrapped: %w", kitErr)
result, ok = FromError(wrapped)
if !ok || !reflect.DeepEqual(result, &kitErr) {
t.Errorf("Expected result to be %#v and ok to be true, got result: %#v, ok: %t", &kitErr, result, ok)
}
}

0 comments on commit b4bce9b

Please sign in to comment.