Skip to content

Commit 7a3cdd2

Browse files
committed
Merge branch 'type_has_trait'
2 parents 01b0a49 + 9f1f883 commit 7a3cdd2

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

error.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ func (e *Error) HasTrait(key Trait) bool {
9494
cause := e
9595
for cause != nil {
9696
if !cause.transparent {
97-
_, ok := cause.errorType.traits[key]
98-
return ok
97+
return cause.errorType.HasTrait(key)
9998
}
10099

101100
cause = Cast(cause.Cause())

type.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ func (t *Type) IsOfType(other *Type) bool {
8888
return false
8989
}
9090

91+
// HasTrait checks if a type possesses the expected trait.
92+
func (t *Type) HasTrait(key Trait) bool {
93+
_, ok := t.traits[key]
94+
return ok
95+
}
96+
9197
// IsOfType is a type check for errors.
9298
// Returns true either if both are of exactly the same type, or if the same is true for one of current type's ancestors.
9399
// For an error that does not have an errorx type, returns false.

0 commit comments

Comments
 (0)