Skip to content

Commit 5dd6248

Browse files
author
oanatmaria
committed
Handle nils correctly
1 parent bdde937 commit 5dd6248

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

Depfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
---
21
go:
32
gotestsum:
43
importPath: "gotest.tools/gotestsum"
54
version: "v1.6.2"
65
golangci-lint:
76
importPath: "github.com/golangci/golangci-lint/cmd/golangci-lint"
8-
version: "v1.46.2"
7+
version: "v1.46.2"

errors.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func NewAsertoError(code string, statusCode codes.Code, httpCode int, msg string
3232
}
3333

3434
// AsertoError represents a well known error
35-
// coming from an Aserto service
35+
// coming from an Aserto service.
3636
type AsertoError struct {
3737
Code string
3838
StatusCode codes.Code
@@ -47,10 +47,10 @@ func (e *AsertoError) Data() map[string]string {
4747
}
4848

4949
// SameAs returns true if the provided error is an AsertoError
50-
// and has the same error code
50+
// and has the same error code.
5151
func (e *AsertoError) SameAs(err error) bool {
5252
aErr, ok := err.(*AsertoError)
53-
if !ok {
53+
if err == nil || !ok {
5454
return false
5555
}
5656

@@ -221,6 +221,10 @@ func (e *AsertoError) Interface(key string, value interface{}) *AsertoError {
221221
}
222222

223223
func (e *AsertoError) Unwrap() error {
224+
if e == nil {
225+
return nil
226+
}
227+
224228
if len(e.errs) > 0 {
225229
return e.errs[len(e.errs)-1]
226230
}

0 commit comments

Comments
 (0)